Fix the 404 on refresh of a SPA on Vercel ("404: NOT_FOUND"), Netlify and Nginx
404: NOT_FOUND Code: NOT_FOUND ID: cdg1::6xk2p-1764323456789-1a2b3c4d5e6f
- Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site.
- 404 Not Found nginx (after refreshing /dashboard in a React app)
- 404 File not found - There isn't a GitHub Pages site here.
- Vercel 404 NOT_FOUND on page reload with React Router
Your React, Vue or Angular app handles its routes in the browser, but when you refresh /dashboard, the host looks for a /dashboard file that does not exist. Add a rule that serves index.html for every route: rewrites in vercel.json, a _redirects file on Netlify, try_files $uri /index.html on Nginx.
What this error means
A SPA (single-page application) is a single index.html file plus JavaScript: React Router, Vue Router or Angular Router change the URL with the History API without reloading the page. As long as you navigate through links, the server is never involved. But on refresh, or when someone opens a direct link, the browser asks the server for /dashboard, which only serves static files and finds nothing: Vercel shows 404: NOT_FOUND, Netlify "Page Not Found", Nginx "404 Not Found". The fix is to tell the server: "if no file matches, serve index.html", and the JavaScript router will render the right page.
Common causes
- No fallback rule to index.html: a Vite, Create React App or Vue CLI app deployed as plain static files.
- Configuration file in the wrong place:
_redirectsmissing from the published folder (dist), orvercel.jsonoutside the project’s "Root Directory". - Wrong output directory: Vercel or Netlify publish the wrong folder, and even
/returns 404. - Purely static hosting (GitHub Pages, S3 bucket) that does not allow server-side rewrites.
Step-by-step fix
-
Confirm it is the SPA case
The home page works and so does link navigation, but a refresh or a direct link to a sub-page gives 404. If even
/is a 404, first check the output directory (distfor Vite,buildfor Create React App).curl -I https://my-app.vercel.app/ curl -I https://my-app.vercel.app/dashboard -
Vercel: add a rewrite
Create
vercel.jsonat the project root (Vercel’s "Root Directory"). Existing files (JS, CSS, images) are still served normally; excludingapi/protects your serverless functions.{ "rewrites": [ { "source": "/((?!api/).*)", "destination": "/index.html" } ] } -
Netlify: _redirects file
The file must end up in the published folder: with Vite or Create React App, put it in
public/, it will be copied todist/orbuild/. Status200makes it a rewrite, not a redirect.# public/_redirects /* /index.html 200 -
Netlify: netlify.toml variant
If you prefer a configuration file at the repository root, use
netlify.toml.[[redirects]] from = "/*" to = "/index.html" status = 200 -
Nginx (or Apache)
On your own server,
try_filesserves the file if it exists, otherwiseindex.html. For Apache,FallbackResource /index.htmlin.htaccessdoes the same.server { listen 80; server_name app.example.com; root /var/www/my-app/dist; index index.html; location / { try_files $uri $uri/ /index.html; } } -
Host without rewrites (GitHub Pages)
Use a hash-based router (
createHashRouterin React Router,createWebHashHistoryin Vue Router): URLs become/#/dashboardand the server only sees/. Copyingindex.htmlto404.htmlalso works, but the page is served with a 404 status, which is bad for SEO. -
Redeploy and test
Redeploy, then open a sub-page directly in a new tab and refresh it. Also check that a truly missing page shows your app’s own 404 page.
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Add the fallback rule (
vercel.json,public/_redirectsor Nginx config) when you create the project and commit it with the code. - Always test a deep URL with a refresh after each deployment, not just the home page.
- Add a catch-all route in your router to show a real in-app 404 page.
Frequently asked questions
Why does it work locally with npm run dev?
The Vite dev server (like Create React App’s) automatically serves index.html for unknown routes. The production host does not, unless configured.
Do Next.js or Nuxt have this problem?
Not in server or hybrid mode: the framework knows its routes. It can come back with a static export (output: 'export') if a dynamic route was not generated.
Will the rule break my JS and CSS files?
No: Vercel, Netlify and try_files serve existing files first, the rewrite only applies to paths with no file.
Useful tools for this error
More DevOps, servers & cloud errors
- Fix "upstream timed out (110: Connection timed out)" and 504 Gateway Time-out in Nginx
- Fix "nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)"
- Fix "413 Request Entity Too Large" (Nginx, PHP, Express, Cloudflare)
- Fix "Certbot failed to authenticate some domains" (Let’s Encrypt, Timeout during connect, acme-challenge 404)
- Fix "Resource not accessible by integration" in GitHub Actions
- Fix "An error occurred (AccessDenied) when calling the PutObject operation" on AWS S3
- Fix "The connection to the server localhost:8080 was refused" with kubectl