In NextJS there is a function getStaticPaths
that tells NextJS which routes are actually available when doing an export. A typical example is a blog that has posts available at /post/[id]
. Let's say there are two posts with the ID's 1
and 2
. In this case, getStaticPaths
would determine and return this information so that NextJS knows, it has to render a site for /posts/1
and /posts/2
when next export
is executed.
I'm wondering what's the equivalent for this in Sapper. I know that there is the preload
function, however, as far as I understand this should be used to fetch the actual post data and does not determine which dynamic routes actually exist at the time of the export.
There's not really an equivalent in Sapper because it works a bit differently. For a Sapper project to be exportable all pages have to be reachable through links from an entry point. Currently, all entry points have to be index pages but there's a Pr open to support files that aren't normally reachable from links on a site, like sitemaps. You can specify multiple entry points. However, with the basic template the entry point is just the main index page. All other pages are discovered by following links from that page.
The code can be found here: https://github.com/sveltejs/sapper/blob/f3e9fc48d281ff990458a4a537a50d59db105e37/src/api/export.ts#L93