I’m deploying a React application built with Vite and using React Router for client-side routing. While the app works perfectly in development, I’m encountering issues when trying to access routes directly after deployment on Vercel. Here’s a summary of the problem:
Problem Description:
The app’s root URL (https://donatexpress.vercel.app/) works fine and I can navigate between pages using the links.
However, when I try to access a route directly (e.g., https://donatexpress.vercel.app/Create), I get a 404: NOT_FOUND error.
App Details:
Built using Vite with React.
Using React Router for client-side routing with <BrowserRouter>.
Thank you for providing such a detailed description of your issue. It seems you’re very close to the solution!
The problem lies in the vercel.json configuration you’ve tried. Instead of using routes, Vercel recommends using rewrites for single-page applications like yours. Here’s the correct configuration:
Replace the content of your vercel.json file with this configuration. This tells Vercel to serve your index.html for all routes, allowing React Router to handle the routing on the client side .
After making this change, commit and redeploy your application. This should resolve the 404 errors you’re experiencing when accessing routes directly.
If you encounter any issues after this change, please let me know, and I’ll be happy to help you troubleshoot further!