Fix 404 on refresh in Vite/React apps on Vercel and Netlify
Navigating via links works, but pressing refresh on /dashboard or /profile throws a 404 Not Found error. Here is the single rewrite configuration that fixes it forever.
Why Single Page Apps (SPAs) Break on Page Refresh
When building with Bolt.new, Lovable, or Vite, client-side routing is managed entirely in browser memory using HTML5 History API. When you click an internal link, the router intercepts the event and renders the component without contacting the web server.
However, the moment a user hits refresh on https://yourapp.com/dashboard, the browser requests /dashboard directly from the web host. Since there is no static file named dashboard.html on disk, the server returns 404.
The Fix for Vercel
Create a file named vercel.json in your root directory:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}The Fix for Netlify
Create a file named _redirects inside your public/ folder:
/* /index.html 200Still seeing routing errors or build failures?
Let us clean up your bundler config, rewrites, and headers today.
Get the White Screen & Deploy Fix
MERN developer in Pakistan fixing React, Node.js, Supabase, and Stripe apps for founders worldwide. About Safdar Rehman
White Screen & Deploy Fix — $99
Fixed price, separate GitHub PR, and Loom walkthrough in 24 hours.
See White Screen & Deploy details