Vercel 404: NOT_FOUND when refreshing a page or opening a direct link

On this page

Short answer

If your app is a Vite single-page app, Vercel only has index.html and asset files, so a direct request for /dashboard finds no file and returns 404. Vercel's Vite guide says deep linking "won't work out of the box" for a SPA. Add the vercel.json rewrite below, commit, and redeploy.

Deploy Without Errors Pack

Environment variables on Vercel, Netlify and Replit, SPA refresh rewrites, npm peer dependency errors and domain setup.

See what’s inside

Secure checkout by Stripe

One-time payment through Stripe. Priced in USD. Local taxes such as UK VAT may be added at checkout.

The exact error you'll see

Vercel's error page in the browser, with HTTP status 404:

NOT_FOUND

Source: https://vercel.com/docs/errors/NOT_FOUND (opens in a new tab)

The home page loads and in-app links work, but refreshing an inner page or opening a shared link shows this error.

Applies to

  • Vite apps configured as a single-page app and deployed to Vercel, including apps exported from Lovable or Bolt
  • Client-side routers such as React Router in browser-only mode
  • The vercel.json file at the project root and its rewrites property

Why it happens

  • No server-side route for each page. In a SPA, the browser draws each page from index.html. Vercel's Vite guide: if the app is "configured to deploy as a Single Page Application (SPA), deep linking won't work out of the box."
  • Missing rewrite. Without a rewrite, Vercel looks for a file at /dashboard, finds none, and returns NOT_FOUND, which Vercel defines as "when a requested resource could not be found."

How to fix it, step by step

  1. In the project root (next to package.json), create or edit vercel.json with Vercel's SPA rewrite from its Vite guide:
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/index.html"
    }
  ]
}

Source: https://vercel.com/docs/frameworks/frontend/vite (opens in a new tab)

  1. If vercel.json already has rewrites, merge this entry into the existing list rather than replacing your rules.
  2. If your vercel.json sets cleanUrls to true, Vercel says not to include the file extension, so /index.html becomes /.
  3. Commit and push, or in Lovable or Bolt ask: "Add a vercel.json at the project root with a rewrite of /(.*) to /index.html." Let Vercel redeploy.

What the docs don't spell out

  • Your images, JavaScript and CSS keep working. Vercel gives "precedence … to the filesystem prior to rewrites being applied," so real files are served first and only unknown paths fall through to index.html. (vercel.json reference (opens in a new tab))
  • Real 404s become your app's job. After the rewrite, every unknown path returns your app instead of Vercel's error, so add a catch-all "not found" route in your router. This follows from the rewrite sending all paths to index.html. (Vercel Vite guide (opens in a new tab))
  • Vercel prefers multi-page builds for production. The same guide says "Deploying your app in Multi-Page App mode is recommended for production builds." The rewrite is the quick fix. (Vercel Vite guide (opens in a new tab))

How to check it worked

  • Open https://yourapp.com/some-inner-page in a new tab and refresh. It loads instead of showing NOT_FOUND.
  • Open a made-up path. Your app's own not-found screen appears.
  • In DevTools' Network tab, a JavaScript or image file still returns the file itself, not the HTML page.
  • Open a deep link the way your users will, such as from an email, a payment provider's success URL or a bookmark, in a private window. It should load the right page, not the home page or an error.

Sources

  1. https://vercel.com/docs/errors/NOT_FOUND (opens in a new tab): NOT_FOUND definition, 404 code
  2. https://vercel.com/docs/frameworks/frontend/vite (opens in a new tab): SPA deep-linking note, vercel.json rewrite, cleanUrls note, Multi-Page App recommendation
  3. https://vercel.com/docs/project-configuration/vercel-json (opens in a new tab): rewrites property, SPA example, filesystem precedence

Tool to consider: Vercel.

Deploy Without Errors Pack

Environment variables on Vercel, Netlify and Replit, SPA refresh rewrites, npm peer dependency errors and domain setup.

See what’s inside

Secure checkout by Stripe

One-time payment through Stripe. Priced in USD. Local taxes such as UK VAT may be added at checkout.