Vibe-Code Rescue

404: NOT_FOUND on Vercel after refreshing a page

Why it happens

A single page app has one real file, index.html. Routes like /dashboard exist only inside the JavaScript router. Click a link and it works. Refresh, or open that URL directly, and the server looks for a file called dashboard, finds nothing and returns 404.

The fix is to tell Vercel to serve index.html for every path and let the router take over.

How to fix it

  1. Confirm the pattern. The home page loads, a link to /dashboard works, and a refresh on /dashboard gives 404: NOT_FOUND.
  2. Create a file named vercel.json in the project root, next to package.json. This is the single page app rewrite from the Vercel docs.
    {
      "$schema": "https://openapi.vercel.sh/vercel.json",
      "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
    }
  3. Commit and push. Vercel builds a new deployment.
    git add vercel.json
    git commit -m "Add SPA rewrite"
    git push
  4. Test a deep link from the command line. You want to see a 200.
    curl -I https://your-app.vercel.app/dashboard
  5. If the app also has API routes under /api, open one after the change to check that it still answers.

When it is not this

Questions

Why does my Vite app 404 on Vercel only when I refresh?

Client-side routes are not real files. On refresh the server looks for a file at that path and finds none. A rewrite to /index.html hands the request to your router.

Where does vercel.json go?

In the project root, next to package.json.

Sources

Still broken?

The free health check asks ten questions about your app and shows the three fixes to do first. It runs in your browser.

If you would rather have someone read the code, the fixed-price audit is $497 one-time. It covers security and scaling, with a written report ranked by severity.