Search code examples
staticsveltesapper

How to export all Sapper routes into static files?


When I run yarn run export / npm run export, only one of my routes get exported as a separate static html file. I want all of them to get exported, into their own .html files.

Am I missing a setting?

The only route exporting is /login

You can check this in this repo (i cannot provide samples, since I don't know what causes this issue): https://github.com/useverto/verto


Solution

  • When sapper export is run you'll see that it first builds the app, runs it, and then crawls the links it finds to determine the routes it can export.

    https://sapper.svelte.dev/docs#How_it_works

    Because the Nav component in your app only exposes / and /login as links when loggedIn is false, the export will only see and follow those links. The /trade and /gallery links in your app are only rendered once loggedIn is true, so they'll not be seen by the export.

    You can add other routes to be exported with the --entry option to the sapper export command. So in your case you could change the export command in package.json to something like...

    "export": "sapper export --legacy --entry '/ trade gallery'",