A React app on Netlify shows 404 when you reload a route
404 Not Found on Netlify when a route is reloadedShort 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.
Fix it fast
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/dashboard2Match what you see, then jump to its fix
- 1
Only the home page loads on a fresh visit; every other route returns 404No rewrite rule exists for client-side routesFix - 2
The rule is in the repo, but the deployed site still returns 404The _redirects file is not in the folder that gets deployedFix - 3
Some routes work and others still 404, or the catch-all is ignored for one pathAn earlier rule matches first, or a real file winsFix
- 1
What does the error look like?
404 Not Found on Netlify when a route is reloadedOpening /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.toml2Fix
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 = 2003Verify
Deploy, then request a deep route. It should return 200.
curl -I https://example.netlify.app/dashboardConfirmed by docs.netlify.com
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/_redirects2Fix
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/_redirects3Verify
Rebuild and confirm the file is in the output.
npm run build
cat dist/_redirectsConfirmed by docs.netlify.com
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.toml2Fix
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/dashboardConfirmed by docs.netlify.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix