Skip to content
  1. LuzineDebug
  2. DevOps, servers & cloud
  3. 404: NOT_FOUND
DevOps, servers & cloud Beginner ≈ 5 min to fix

Fix the 404 on refresh of a SPA on Vercel ("404: NOT_FOUND"), Netlify and Nginx

Error message
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
In short

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.

Be the first to confirm this fix

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

  1. No fallback rule to index.html: a Vite, Create React App or Vue CLI app deployed as plain static files.
  2. Configuration file in the wrong place: _redirects missing from the published folder (dist), or vercel.json outside the project’s "Root Directory".
  3. Wrong output directory: Vercel or Netlify publish the wrong folder, and even / returns 404.
  4. Purely static hosting (GitHub Pages, S3 bucket) that does not allow server-side rewrites.

Step-by-step fix

  1. 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 (dist for Vite, build for Create React App).

    bash
    curl -I https://my-app.vercel.app/
    curl -I https://my-app.vercel.app/dashboard
  2. Vercel: add a rewrite

    Create vercel.json at the project root (Vercel’s "Root Directory"). Existing files (JS, CSS, images) are still served normally; excluding api/ protects your serverless functions.

    json
    {
      "rewrites": [
        { "source": "/((?!api/).*)", "destination": "/index.html" }
      ]
    }
  3. 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 to dist/ or build/. Status 200 makes it a rewrite, not a redirect.

    plaintext
    # public/_redirects
    /*    /index.html   200
  4. Netlify: netlify.toml variant

    If you prefer a configuration file at the repository root, use netlify.toml.

    ini
    [[redirects]]
      from = "/*"
      to = "/index.html"
      status = 200
  5. Nginx (or Apache)

    On your own server, try_files serves the file if it exists, otherwise index.html. For Apache, FallbackResource /index.html in .htaccess does the same.

    nginx
    server {
        listen 80;
        server_name app.example.com;
        root /var/www/my-app/dist;
        index index.html;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
  6. Host without rewrites (GitHub Pages)

    Use a hash-based router (createHashRouter in React Router, createWebHashHistory in Vue Router): URLs become /#/dashboard and the server only sees /. Copying index.html to 404.html also works, but the page is served with a 404 status, which is bad for SEO.

  7. 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/_redirects or 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

All DevOps, servers & cloud errors →