Source:  Twitter logo

I am developping a website with vite which seem work like it should on localhost.
I deployed on Vercel and the site was build without errors.
But I discovered a big problem when I wanted to generate my sourcemaps. In fact, when I want to visit any page directly (.../about for example) vercel sends me a "404 not found" error. But when I go to the root page and navigate to the page manually everything is working. Second time i visit the /about page directly, it works, but because it has been cached by my browser i think ...

hosting : vercel
base url:
404 example url :

used plugins :

  • vite-plugin-pages
  • vue-router (v4)
  • vite-ssg

I can give the github link if needed, but i think this is mostly a vercel problem ? I found a linked problem on stackoverflow, but with React (link)

Answer found here :
Credit goes to shantiscrip

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

Add rewrites for all routes to the file that point to '/'

  "rewrites": [{ "source": "/(.*)", "destination": "/" }]
0 users liked answer #0dislike answer #00
Benjamin Fourgeaud profile pic
Benjamin Fourgeaud

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).