Netlify React Router Not Working?
You have created your Website .And you have chosen netlify to host it.But when you deploy it on netlify and try to open a specific routes then ,it gives an error.It should look like this:
It happens because React-router handles routing on the client side.
So, if you try to visit a specific route in your browser other than the root route, https://example.netlify.com/about, Netlify doesn’t know how to locate that route on the server side.
3 Steps to Fix Netlify React Router Error problem:
- Go to your react app’s
/publicfolder. And create a plain text file called_redirectswithout a file extension. - Add the following code into the
_redirectsfile:/* /index.html 200 - Build and publish your app again. It should fix the Netlify page not found error.
If you already have a
netlify.tomlfile created in the root directory of the app
- Add the following codes in the
netlify.tomlfile:
‘ [[redirects]] ’
from = "/*"
to = "/index.html"
status = 200
Build and deploy your application again in Netlify it works like magic!
