'React, after deployment on netlify routes give 404 page not found on refesh
I am trying to learn how to fix the following issue.
- After deploying my react app on netlify, when I refresh any of my routes at https://candid-cobbler-cd2c3e.netlify.app/ or manually load https://candid-cobbler-cd2c3e.netlify.app/red it gives me a 404 page not found error.
The site works find if I use buttons to navigate.
Solutions that I have tried so for :
_redirects was added to the root folder with
/* /index.html 200built and re-deployed. Did Not Worknetlify.toml was added to root folder
[[redirects]] from = "/*" to = "/" status = 200built and re-deployed Did Not Work
Take a look at my files : https://github.com/swappybizz/routing_refresh_on_deployment/
Solution 1:[1]
There is a useful tutorial by hBlev : https://www.youtube.com/watch?v=e6qXUS3C550 where at 10:00 , it has been explained the following :
- Netlify serves only
Index.html - Everything in the
Publicdirectory gets build andsrcgets bundled. - The
_redirectshas to be in thePublicdirectory for the routing to work on refresh or manual loading - The statement
/* /index.html 200is a to from statusCode and the*represents all possibilities and it is going to redirect them toindex.htmlwhich is actually the only thing served. Buth the status code200helps keep the/pathand not letting it redirect to the url but Render while keeping the path
details could be found [here]:https://docs.netlify.com/routing/overview/
Same site was redeployed to https://teal-mermaid-ada4e6.netlify.app and now routes could be refreshed or directly loaded i.e by clicking https://teal-mermaid-ada4e6.netlify.app/red
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | swapnil Kumar |
