Home > Software design >  why React production build only shows the 404 page without the rest of the page?
why React production build only shows the 404 page without the rest of the page?

Time:03-01

I created a website with react and I'm using react-router-dom I want to deploy it to netlify, so i run npm run build but when I click the index.html. It only shows the route I created for the non-existing path i.e 404 page, How do I go about displaying the Homepage and the rest of the page?

CodePudding user response:

Add a netlify.toml file to the root of your project and add the following lines. Then re-deploy on Netlify.

Redirects and rewrites

This is necessary to instruct netlify to redirect all routes to your app. So that react-router-dom can handle routing internally.

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