Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

A React app on Netlify shows 404 when you reload a route

Error404 Not Found on Netlify when a route is reloaded

Short answer

Netlify looks for a real file at the URL you reload, finds none for a client-side route like /dashboard, and returns 404. Add one rewrite rule, /* to /index.html with status 200, in a _redirects file inside the publish folder or in netlify.toml. React Router then reads the URL and draws the page.

  • Applies to Netlify redirects, React 19, React Router 7, Vite
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Request a deep route directly and look at the status line. A 404 on a route that works inside the app confirms the server has no rule for it.

    curl -I https://example.netlify.app/dashboard
  2. 2Match what you see, then jump to its fix

    1. 1Only the home page loads on a fresh visit; every other route returns 404No rewrite rule exists for client-side routesFix
    2. 2The rule is in the repo, but the deployed site still returns 404The _redirects file is not in the folder that gets deployedFix
    3. 3Some routes work and others still 404, or the catch-all is ignored for one pathAn earlier rule matches first, or a real file winsFix

What does the error look like?

  • 404 Not Found on Netlify when a route is reloaded
  • Opening /about from a link works; pressing refresh or pasting the URL gives 404

Cause 1 of 3

No rewrite rule exists for client-side routes

1Check

A single-page app has one real file, index.html. Routes such as /dashboard exist only in JavaScript, so Netlify has nothing to serve for them. Check that your project has no rule at all.

ls public/_redirects 2>/dev/null
grep -n "redirects" netlify.toml

2Fix

Add a catch-all rewrite. Status 200 makes it a rewrite, so the address bar keeps the URL and Netlify serves index.html. Use either the file form or the netlify.toml form, not both.

# public/_redirects
/*  /index.html  200

# or in netlify.toml
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

3Verify

Deploy, then request a deep route. It should return 200.

curl -I https://example.netlify.app/dashboard

Confirmed by docs.netlify.com

Did this fix it?

Cause 2 of 3

The _redirects file is not in the folder that gets deployed

1Check

Netlify reads _redirects from the publish directory, the build output, not from the repo root. In a Vite app the build output is dist, so the file must end up there.

npm run build
ls dist/_redirects

2Fix

Put the file in the folder your tool copies to the output as-is (public/ in Vite), or use the netlify.toml form, which does not depend on the build output.

mkdir -p public
printf '/*  /index.html  200\n' > public/_redirects

3Verify

Rebuild and confirm the file is in the output.

npm run build
cat dist/_redirects

Confirmed by docs.netlify.com

Did this fix it?

Cause 3 of 3

An earlier rule matches first, or a real file wins

1Check

Netlify uses the first matching rule from top to bottom, and rules in _redirects run before those in netlify.toml. A rewrite also does not override a URL that matches a real file, so a folder or file with the same path as a route is served instead.

cat public/_redirects
grep -n -A4 "redirects" netlify.toml

2Fix

Keep the catch-all as the last rule, and remove or rename a file or folder that shares a path with a route. If you need the rewrite to win over a file, add ! to the status in _redirects, or force = true in netlify.toml.

/api/*  https://api.example.com/:splat  200
/*      /index.html                      200!

3Verify

Request the route that failed after the next deploy.

curl -I https://example.netlify.app/dashboard

Confirmed by docs.netlify.com

Did this fix it?

How do I stop it coming back?

  • Commit the redirect rule with the first deploy of any single-page app, not after the first bug report.
  • Keep the catch-all as the last rule, below any proxy or redirect rules.
  • Check deep links in a deploy preview before merging a routing change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.