-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Clicking anchor links to valid static files results in a 404 and $error component showing #1295
Comments
I suspect that adding |
Ah, yeah, I think I misunderstood the docs on this one. They say:
So I took it to mean you need The behavior is more like "the SvelteKit runtime intercepts clicks on Put another way, I expected it to be more like:
I've got a handful of documents in markdown that link to internal static files, so I'll have to update my MD->HTML conversion to add rel=external to anchors or update them to use HTML for the links or have the runtime add the Happy to submit a little PR to the docs around this if you think it'd be helpful |
I think it's weird that you have to put |
Couldn't this be done automatically, with neither |
But then we'd have to send a list of all assets to the client which would increase transfer latency |
Why would it have to be sent to the client ? It is known at compile time, so the |
I suppose you could write a preprocessor that would automatically add |
So there is no way to efficiently solve this bug ? Maybe sveltekit navigation could just attempt a normal browser navigation whenever a route is not found ? |
What about links that you don't know the exact href of ahead of time? For example those set in a CMS, where it might link to a valid route or a file, both 'internal' assuming assets are downloaded SSG style at build time. |
I think using sveltekit needs an attribute to handle the cases of dynamic links and/or content pulled from a CMS, but it should be named something like That said, it would be nice in the long-term for sveltekit to automatically handle this for the cases it can. |
because svelteKit intercepts normal anchor behaviour it tries to route to a page with the assets path. It does not exist, so it generates an error. See sveltejs/kit#1295
This isn't the case anymore since |
Describe the bug
I noticed this when updating from
@sveltejs/kit
from next-84 to next-94. If you have an<a href="/some-static-file.png">
link to any static asset, when you click the link, the SPA renders the $error layout with a 404 Not Found.Logs
There's nothing in the console, but the stack on the $error page has the following:
To Reproduce
I have a quick public repo with a minimal change to the sample project here if you want to pull that down: https://github.com/leereamsnyder/sveltekit-static-file-link-busted/blob/768fe93c2974ece2538be30a3d75c2af6cccd29b/src/routes/index.svelte#L29-L32
npm run dev
<a href="svelte-welcome.png">link to an image</a>
Expected behavior
The browser should render the static file instead of the SPA rendering an $error page.
Stacktraces
If you have a stack trace to include, we recommend putting inside a
<details>
block for the sake of the thread's readability:Stack trace from the $error component
Information about your SvelteKit Installation:
Diagnostics
npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
:Your browser: Firefox 88.0 64 Bit
Your adapter (e.g. Node, static, Vercel, Begin, etc...): this happens in development and with adapter-static
Severity
This is blocking my upgrade to the latest SvelteKit, but I could roll back to next-84 and it was fine.
The text was updated successfully, but these errors were encountered: