You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, SvelteKit will find pages to prerender by starting at every parameter-less route (we call these entries), prerendering them (if possible), and crawling the resulting HTML to find new links.
You can specify new entries in svelte.config.js if you have pages that need to be prerendered but which are not, for whatever reason, findable by following <a> tags.
This works, but the ergonomics aren't super great, and there's no type safety.
In entries was specified for a page, the resulting entries would be included in *, meaning that they would be included by default, but you would still have total control over which entries were considered:
exportdefault{kit: {prerender: {// this is the default config, so can be omittedentries: ['*']// include all parameter-less routes, plus pages that specify `entries`}}};exportdefault{kit: {prerender: {entries: ['*','/x/y/z']// include all of the above _plus_ `/x/y/z`}}};exportdefault{kit: {prerender: {entries: ['/x/y/z']// only prerender `/x/y/z`}}};
For consistency we should probably allow the same for +server.js files.
The text was updated successfully, but these errors were encountered:
One question though: Why is the return type Array<{ slug: string }>? Could just be Array<string>? Unless you plan to provide other options in the returning array... 🤔
We can provide type-safety for the params you return -- i.e. if you're on /[year]/[month]/[[day]] we can enforce that the type you return is Array<{ year: string, month: string, day?: string }>. This provides a great deal more safety than just returning a string does! If you want to provide an Array<string>, though, the top-level config option still remains.
LOVE this idea, the crawler is great as a default but relying on it solely has been a footgun a few times for me. For example something as simple as building a blog — if there aren’t any posts yet sveltekit errors out saying the page can’t be pre-rendered because it’s not linked to
Describe the problem
By default, SvelteKit will find pages to prerender by starting at every parameter-less route (we call these entries), prerendering them (if possible), and crawling the resulting HTML to find new links.
You can specify new entries in
svelte.config.js
if you have pages that need to be prerendered but which are not, for whatever reason, findable by following<a>
tags.This works, but the ergonomics aren't super great, and there's no type safety.
Describe the proposed solution
Next has a couple of solutions to this —
getStaticPaths
for old apps, andgenerateStaticParams
if you're using the App Router.We could have our own version of
generateStaticParams
— for consistency with the configuration option, I'd proposeentries
:The return value could be typed (including automatically, thanks to https://svelte.dev/blog/zero-config-type-safety).
In
entries
was specified for a page, the resulting entries would be included in*
, meaning that they would be included by default, but you would still have total control over which entries were considered:For consistency we should probably allow the same for
+server.js
files.The text was updated successfully, but these errors were encountered: