0

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.

jz22
  • 2,328
  • 5
  • 31
  • 50

1 Answers1

1

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

digby280
  • 879
  • 1
  • 7
  • 22
  • Thanks for your answer. Just to make sure I understood it correctly, at the moment it would not fetch and export all blog posts as they are not explicitly linked in the index file or somewhere else. – jz22 Jul 14 '20 at 00:31
  • Yes. That's correct. It basically crawls your site starting at the entry points and discovers all the pages. If a page cannot be reached directly or indirectly from an entry point it will not be exported. The PR I mentioned is here: https://github.com/sveltejs/sapper/pull/1288. If that gets merged you'll be able to add other pages as entry points. – digby280 Jul 14 '20 at 05:51
  • This should cover anything I've missed: https://sapper.svelte.dev/docs#Exporting – digby280 Jul 14 '20 at 05:55