Home / Error library / Vercel 404 on refresh

VercelLovable · Bolt · ViteCommon deploy bug

Vercel 404 on refresh: the SPA routing fix

The home page loads. Clicking to /dashboard or /login works. Then you refresh, or share the link, and Vercel shows a 404. Here's what that means and how to fix it.

404: NOT_FOUND
Code: NOT_FOUND

The homepage is fine. The 404 shows up only when you refresh an inner route, open it in a new tab, or paste the URL. This is not the same as a blank white page after publish.

Short answer

Your app is a single-page app (SPA). Clicks change the URL in the browser without asking the server for a new file. A refresh or a shared link does ask Vercel for a file at that path — and there is no /dashboard.html, so you get 404. The fix is a catch-all rewrite in vercel.json that serves index.html and lets React Router (or Vue Router) handle the route.

What the error means

Vite, Create React App, and most Lovable or Bolt apps ship one HTML file: index.html. Your router then draws /dashboard, /settings, and the rest in the browser. That works on the Vite dev server and in the editor preview, because those tools already fall back to index.html.

Vercel does not assume that. Per Vercel's docs, it "resolves every URL as a server-side filesystem path by default." So:

  1. Clicking a link inside the app works. The browser never asks Vercel for /dashboard.
  2. Refresh, a new tab, or a shared link fails. The browser asks Vercel for that path, no file matches, and you get 404: NOT_FOUND.

If the homepage itself is a 404, this is not your bug. Check the Framework Preset (it should be Vite, not Other) and the output directory. If the *.vercel.app URL works but your custom domain 404s, that's DNS, not routing.

Why the AI caused it

In Lovable or Bolt, the preview already handles client routes, so the AI never has to think about hosting. It writes BrowserRouter (or the Vue equivalent) and ships the app. When you export the repo to Vercel, nothing tells Vercel to fall back to index.html.

The AI will often "fix" it by switching to HashRouter (ugly /#/dashboard URLs) or by adding a rewrite so aggressive that it also swallows /api routes. Don't let it do either. Add the official SPA rewrite and redeploy.

Step-by-step fix

  1. Confirm it's this 404, not a crash. Open the home URL — it should load. Click through to an inner page — it should load. Then refresh that inner page, or paste the URL in a private window. If you now see Vercel's 404, continue. If you see a blank white page, use the blank page fix instead.
  2. Add vercel.json at the project root (next to package.json, not inside dist/ or src/). For a plain Vite SPA:
    {
      "rewrites": [
        { "source": "/(.*)", "destination": "/index.html" }
      ]
    }
    If you also have API routes under /api, exclude them so those calls are not turned into HTML:
    {
      "rewrites": [
        { "source": "/((?!api/).*)", "destination": "/index.html" }
      ]
    }
    If cleanUrls is already true in this file, use "destination": "/index" (no .html).
  3. Commit the file and redeploy. vercel.json has to be at the repo root and included in the deploy. Saving it locally does not change a build that already shipped. Push, or click Deploy / Publish again.
  4. Test the three cases. Home still loads. An inner route still loads when you click to it. Refresh on that inner route, and open the same URL in a private window — both should load your app, not 404.
  5. If you published to Netlify or Cloudflare Pages instead. Add a _redirects file at the project root (or in the published folder your host expects) with:
    /*    /index.html   200
    Then republish. The idea is the same: unknown paths should serve index.html.
Don't "fix" it this way: switching to HashRouter just to avoid the 404, rewriting /api into index.html, or pasting this catch-all into a Next.js, SvelteKit, or Nuxt project. Those frameworks have their own routing, and this rewrite can break them.

Copy-paste prompt for your AI tool

Paste this into Lovable, Bolt, Replit Agent or Cursor.

My Vite / React (or Vue) SPA is deployed on Vercel. The homepage and
in-app clicks work, but refreshing an inner route (or opening that URL
directly) returns Vercel's 404: NOT_FOUND.

Please:
1. Add a vercel.json at the project root with a catch-all SPA rewrite
   to /index.html, following Vercel's Vite SPA docs.
2. If the project has /api routes, exclude them from the rewrite
   (source should skip /api/).
3. If cleanUrls is already true, use destination "/index" not
   "/index.html".
4. Do NOT switch to HashRouter, do NOT add this rewrite if the app is
   Next.js, SvelteKit, or Nuxt, and do NOT rewrite API routes to HTML.
5. Remind me I must commit the file and redeploy, then test refresh
   and a direct link on an inner route.

If this project is on Netlify or Cloudflare Pages instead, add the
equivalent _redirects rule (/* /index.html 200) and tell me where
to put the file.

FAQ

Why does my Vercel app 404 when I refresh a page?

Your app is a single-page app. Clicks change the URL in the browser, but a refresh or a shared link asks Vercel for a real file at that path. There is no /dashboard.html, so Vercel returns 404. The fix is a catch-all rewrite in vercel.json that serves index.html and lets your router take over.

Is this the same as a blank white page after publish?

No. A blank white page usually means the live JavaScript crashed, often from a missing VITE_ environment variable. A refresh 404 is a host routing issue: the homepage may work, but inner routes return Vercel's 404 page. See Lovable blank white page after publish.

Do I need this rewrite if I use Next.js?

No. This vercel.json catch-all is for Vite, Create React App, and similar SPAs. Next.js, SvelteKit, and Nuxt have their own routing. Adding this rewrite on those frameworks can break API routes and pages.

I added vercel.json and still get 404. Why?

The file has to sit at the repository root, be committed, and be included in a new deploy. Saving it does not change a build that already shipped. Also check that the Framework Preset is Vite (not Other), and that you are not using cleanUrls with a destination of /index.html.

Does this also happen on Netlify or Cloudflare?

Yes. The same SPA rule applies. On Netlify or Cloudflare Pages, add a _redirects file with: /* /index.html 200. Then republish.

Fixed the 404? Check what else is open.

A missing rewrite is the loud failure. The quiet ones are keys in your frontend, tables with RLS off, and auth that only looks like it works. The $15 pre-launch safety check finds them and gives you paste-in fix prompts.

Pay $15 & start check →

Target turnaround 24h · Refund if it finds nothing useful

Sources

Last reviewed Nov 16, 2026. Unbreak My Code is independent and not affiliated with Vercel, Vite, Lovable or Bolt.

Get new fix pages by email. No spam, unsubscribe anytime.