Why React Router Breaks After Deployment (and How to Fix It)
React Router often breaks after deploy. Here is why, and the fix for each major host.
Why React Router Breaks After Deployment (and How to Fix It)
A common deploy bug: the home page works, but any deep link returns a 404. Here is why React Router breaks after deployment and how to fix it.
Why It Happens
In development, the dev server serves index.html for all routes. In production, the host serves files from a folder, and any route that is not a real file returns a 404. Client-side routes are not real files.
The Fix: Redirect to index.html
Configure the host to redirect all routes to index.html. Then React Router loads, reads the URL, and renders the right component. This is the standard fix.
Vercel
Vercel usually handles this for React apps automatically. If not, add a rewrite rule in vercel.json that redirects all routes to index.html.
Netlify
Add a _redirects file in your public folder with the line '/* /index.html 200', which redirects all routes to index.html with a 200 status.
Firebase Hosting
In firebase.json, configure the rewrites section to redirect all routes to /index.html. This makes Firebase serve index.html for any route.
Verify After Deploy
After deploying, visit a deep link directly, like /browse, and confirm it renders the right page. If it 404s, your rewrite rule is missing or wrong.
The Takeaway
React Router breaks on deploy because the host serves 404 for routes that are not files. Fix it by redirecting all routes to index.html, with a rewrite rule in Vercel, a _redirects file in Netlify, or rewrites in firebase.json.
Because the host serves a 404 for routes that are not real files. In development, the dev server serves index.html for all routes, but in production, client-side routes are not files, so the host returns 404. Fix by redirecting all routes to index.html.
Vercel usually handles this for React apps automatically. If not, add a rewrite rule in vercel.json that redirects all routes to index.html, so React Router loads and handles the route client-side.
Add a _redirects file in your public folder with the line '/* /index.html 200'. This redirects all routes to index.html with a 200 status, so React Router handles the routing client-side.
In firebase.json, configure the rewrites section to redirect all routes to /index.html. This makes Firebase serve index.html for any route, so React Router loads and handles it client-side.
Visit a deep link directly in your browser, like /browse, and confirm it renders the right page. If it returns a 404, your rewrite rule is missing or wrong. Always test deep links after deploying.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

