404 NOT_FOUND when refreshing a page (React/Vite SPA)
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
- On Vercel add vercel.json: {"rewrites":[{"source":"/(.*)","destination":"/index.html"}]}
- On Netlify add public/_redirects with: /* /index.html 200
- Redeploy and test a deep link.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
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.
Related fixes
- Vercel build fails: Type error / ESLint errors (works locally)
- CORS error: blocked by CORS policy: No 'Access-Control-Allow-Origin' header
- Replit deploy: app not reachable / port not open
- Hydration failed because the server rendered HTML didn't match the client
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.