404 failure with static adapter for sveltekit

Not sure if this is on SvelteKit since there is an open issue for this but there is a weird error issue with nested routes. We created a blog and we are simply at this point just listing out the links in the index but unfortunately, we are getting this error Error: 404 /blog/blog/test-post (linked from /blog/test-post).
when commented out everything works fine

        {#each posts as post}
            <li class="ml-8 my-2">
                <a sveltekit:prefetch href="blog/{post.uid}">

The kit config is below

	kit: {
		adapter: adapter({
			// default options are shown
			pages: 'build',
			assets: 'build',
			fallback: null
		target: '#svelte'

Hi Teddy,

I would guess it is because a trailing slash is missing at the very beginning of your dynamic link : href="/blog/{post.uid}" instead of href="blog/{post.uid}"

Have a great day

Unfortunately, I have tried that even adding a config in the svelte config to require a backslash but still no success. I had it working before but then the magic dissapeared.

Hey Team,

I'll be honest I don't know anything about svelte, but from reading about sveltekit:prefetch:

  • prefetch(href) programmatically prefetches the given page, which means a) ensuring that the code for the page is loaded, and b) calling the page's load function with the appropriate options. This is the same behaviour that SvelteKit triggers when the user taps or mouses over an <a> element with sveltekit:prefetch. If the next navigation is to href , the values returned from load will be used, making navigation instantaneous. Returns a Promise that resolves when the prefetch is complete.

I'm guessing you'll need to pass the link resolver function for your link to be created correctly.

So your link would look something like this:

<a sveltekit:prefetch href="linkresolver(post)">
1 Like

That was a possible solution I was looking into. For now, I decided to move from the static adapter to the netlify adapter and that is working just fine for now but I will take a look at this solution and report back.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.