Search code examples
javascriptsveltesveltekit

Svelte prerender with 'dynamic' route


I am trying to use svelte SSG because all of my data is fetched from an external API. All of my routes are being generated except for one route because it has parameters. It looks something like this:

"/user/[userId]/code/[code]"

That route is used as email verification. It isn't accessed anywhere in the code because the server sends an email. However, because of the parameters (and I guess because the route is not elsewhere in the code) it will not generate a proper route for that.

I tried putting two examples in 'svelte.config.js' in 'kit.prerender.entries' but it just creates two routes that exactly match the userId and code.

The JS in the page just gets the data from the URL, takes some user input and then makes a fetch request, so it can be prerendered.

Is there any way to have dynamic routes such as this in Svelte SSG or is that just impossible?


Solution

  • Pre-rendering of routes with parameters is not possible unless all possible parameter values are known/specified at build time.

    Disable pre-rendering for that specific route. Since no HTML file for the route exists, the server then should serve the fallback page and SvelteKit will dynamically render the correct route.