Sitemap

Netlify React Router Not Working?

1 min readMay 12, 2023

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:

  1. Go to your react app’s /public folder. And create a plain text file called _redirects without a file extension.
  2. Add the following code into the _redirects file: /* /index.html 200
  3. Build and publish your app again. It should fix the Netlify page not found error.

If you already have a netlify.toml file created in the root directory of the app

  1. Add the following codes in the netlify.toml file:

[[redirects]]
from = "/*"
to = "/index.html"
status = 200

Build and deploy your application again in Netlify it works like magic!

--

--

Tonmoy
Tonmoy

Written by Tonmoy

Hands-on Polyglot Full Stack Developer| Backend enthusiast 🚀

Responses (6)