This is my first time deploying a react app on AWS Amplify. The app works fine as a SPA, the only problem is re-directions.
For example; when a user completely signs up and gets a link to verify email, clicking on the link redirects me to mydomain.com/index.html.
Also when i try navigating to mydomain.com/sign-in (which should lead me to sign in page), it redirects me to mydomain.com/index.html.
How can i resolve this?
Try going to App settings->Rewrites and redirects
Add in a new rule
</^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
index.html
200 (Rewrite)
Here's an example of what the end result should look like.
If that doesn't work, try this one
</^((?!.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
You need to accept and route all files. When react builds, it runs off the index
file, but react-router manipulates the path as SPA requirements have it.
Paste this into your rewrites and redirects. This will generally work if you are running a standard react router webapp.
[
{
"source": "</^((?!\\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>",
"target": "/index.html",
"status": "200",
"condition": null
},
{
"source": "/<*>",
"target": "/",
"status": "404",
"condition": null
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With