Tried everything to fix react router 404 page not found but nothing is working

I deployed my React app but cannot directly type any react-router url paths (like (^◡^✿) hello!) or else I get the 404 page not found error screen.

  • I already created a _redirects file containing /* /index.html 200 that lives inside my public directory

  • I already created a netlify.toml with a special command that I thought could fix this _redirects issue:

[build]
  command = "npm run build && cp _redirects dist/_redirects"
  publish = "dist"

 [[redirects]]
  from = "https://christinetrac.dev"
  to = "https://www.christinetrac.dev"

None of these things worked, and I still get an error page. Any idea how I can fix this?

This is my deploy log: Netlify App

I’ve found the solution. I followed this exactly: reactjs - netlify deployment: Failed during stage 'building site': Build script returned non-zero exit code: 2 - Stack Overflow

This is my resulting netlify.toml file:

[build]
  command = "CI= npm run build"
  publish = "build"

 [[redirects]]
  from = "https://christinetrac.dev"
  to = "https://www.christinetrac.dev"

Great you found a solution @nuggetchristine.

Would like to point out there is documentation on Netlify here and on the Create React App website here which mention the the publish directory for CRA is build.

1 Like