# 404 NOT_FOUND when refreshing a page (React/Vite SPA)

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/vercel-404-on-refresh-spa.html
> Category: Deploys | Tools: Lovable, Bolt | Published: 2026-10-13 | Updated: 2026-10-13

## The error

404: NOT_FOUND on /dashboard after refresh or when opening a direct link

## Why it happens

Vite/React Router apps are single-page apps: only index.html exists. The host looks for a /dashboard file, finds none and returns 404. You need a rewrite to index.html.

## How to fix it

1. On Vercel add vercel.json: {"rewrites":[{"source":"/(.*)","destination":"/index.html"}]}
2. On Netlify add public/_redirects with: /*  /index.html  200
3. Redeploy and test a deep link.

## Error codes this fixes

- `404: NOT_FOUND on refresh` (Vercel): https://unbreakmyapp.vercel.app/errors.html#404-not-found-on-refresh

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
Direct links and refreshes on routes like /dashboard return 404 after deploying this Vite + React Router app. Add the correct SPA fallback for <Vercel/Netlify> (vercel.json rewrites to /index.html, or a _redirects file) without breaking /api routes, and confirm deep links work.
```

## FAQ

### Why does the home page work?

/ maps to index.html, which exists; other paths don't.

### Will this break API routes?

Vercel serves real files and functions before applying rewrites.

## Sources (official documentation)

- [Vercel: Project Configuration (rewrites)](https://vercel.com/docs/project-configuration#rewrites)

## Related fixes

- [App works on localhost but breaks in production: a checklist to find the cause](https://unbreakmyapp.vercel.app/fixes/works-on-localhost-breaks-in-production.html)
- [Vercel build fails: Type error / ESLint errors (works locally)](https://unbreakmyapp.vercel.app/fixes/vercel-build-failed-type-errors.html)
- [CORS error: blocked by CORS policy: No 'Access-Control-Allow-Origin' header](https://unbreakmyapp.vercel.app/fixes/cors-error-fetch-blocked.html)
- [Replit deploy: app not reachable / port not open](https://unbreakmyapp.vercel.app/fixes/replit-port-not-open.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
