Failing to generate dynamic routes with Sapper export

邮差的信 提交于 2020-12-12 10:00:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!