-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic routes are broken #24
Comments
For anyone looking for a temporary if very hacky workaround, I've added a fetch event handler in my service worker to work around this: // service-worker.ts
// add this before workbox registerRoute(...)
self.addEventListener('fetch', (event: FetchEvent) => {
const url = new URL(event.request.url)
if (url.pathname.includes('/_app/') && !url.pathname.startsWith('/_app/')) {
url.pathname = replaceBeforeSubstring(url.pathname, '/_app/')
return event.respondWith(caches.match(url))
}
}) |
I am struggling with this exact same issue using I'm prerendering and precaching the root page and setting I tried to add dynamic routes to Did anyone find a stable solution to this? Or is the better bet to just prerender and handle everything dynamic in regular Svelte components? |
Found the answer! The issue seems entirely related to the SvelteKit build process and not the service worker / PWA plugin. Setting this
in |
The generated asset links on dynamic pages are relative to the current directory instead of the root, resulting in prefixing the current URL to the asset requests which do not exist.
Navigating to pages with the client side router works correctly. The only problem is when you open the page to a page that isn't prerendered or refresh the page on a page that isn't prerendered that you encounter the problem.
I've tested the normal example produced with
npm create svelte@latest my-app
and it correctly generates relative links to the assets.Issue reproduction: https://github.com/meticoeus/sveltekit. See the modified example
I've made minimum modifications to the example to switch to the new auto adapter and add a dynamic route page that imports a component to show the problem.
Example generated html for route
/about/[id]
in.svelte-kit/output/
:The text was updated successfully, but these errors were encountered: