Accepted answer

This is not a problem with vite.js but due to with a missing configuration file for vercel which is added by default to the existing templates. For a single page application the html files for the routes created with react router don't exist, so something on the server needs to create rewrites to make sure every request points at '/' or index.html. In Vercel this can be done by adding a rewrite to config file in the root of the project called

vercel.json Add rewrites for all routes to the file that point to '/' or '/index.html'

  "rewrites": [{ "source": "/(.*)", "destination": "/" }]


  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]


If you are using vite create a folder called public and add a file called _redirects to it, for the rest of the other bundlers just add the _redirects file to the public folder

Related Query

More Query from same tag