问题
I have a dynamic route:
routes/artwork/[slug].svelte
.
All works great with npm run dev
.
But when I npm run export
those dynamic slug routes are missing. I don't see them in the __sapper__/export
, and the pages are missing as well when I uploaded to Netlify.
Any clue how I might be able to fix that? Did I miss something obvious?
回答1:
sapper export
works by building your app, running it, then visiting /
and recursively visiting every internal link it finds. For that reason, it has to be possible to get to /artwork/foo
and /artwork/bar
etc by following links from the home page (e.g. via a routes/artwork/index.svelte
page, which would map to /artwork
).
回答2:
To add additional context to Rich Harris's answer:
If a similar route URL is crawled incorrectly before the dynamic routes are, it won't try to generate the dynamic route.
A homepage link uses "/events/slug"
instead of href="events/slug"
, the dev site will correctly provide a 404 on the homepage link, and serve the dynamic slugs on the events page. But, on build, the slugs will not be generated at all.
来源:https://stackoverflow.com/questions/58501974/failing-to-generate-dynamic-routes-with-sapper-export