jorgegorka / svelte-router

Svelte Router adds routing to your Svelte apps. It's designed for Single Page Applications (SPA). Includes localisation, guards and nested layouts.
MIT License
508 stars 42 forks source link

Netlify, Vite and SPA mode #138

Open cliveportman opened 1 year ago

cliveportman commented 1 year ago

Deploying to Netlify, I've always found adding "start": "sirv public -s"

to sort out the issue of routes returning a 404. But it's not working for me with this project. Is it Vite? If so, what's the solution? Adding the same to package.json makes no difference.

Kokoserver commented 1 year ago

Please can anyone answer this

ktunprasert commented 1 year ago

You need to add a rewrite rule when deploying to vercel. Here is an example vercel.json on your root directory (next to package.json) https://vercel.com/docs/project-configuration

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

The above example will rewrite all path to your root destination, meaning every request to any path will be served by your SPA router.