I have a very basic sveltekit project(:3000
) with a simple route structure that consumes a backend(:5000
):
├── ./src
│ ├── ./src/app.html
│ ├── ./src/routes
│ │ ├── ./src/routes/index.svelte
│ │ ├── ./src/routes/__layout.svelte
│ │ └── ./src/routes/view
│ │ ├── ./src/routes/view/[id].svelte
│ │ └── ./src/routes/view/index.svelte
Imagine a listing of companys in routes/index.svelte
which prefetches on hovering the data of the listed companys with <a sveltekit:prefetch href="/view/${company._id}">...</a>
.
In Chrome devtools it shows that this is working correctly, with http://localhost:5000/company/6203a1d7c36d6f78f5979f26
. Yet for some reason, as soon as I click the link, sveltekit is fetching for http://localhost:3000/view/favicon.png
, which obviously does not exists, because it is living in app/src/static/favicon.png
.
Does anybody have ever seen this? Am I missing an obvious point on how to handle static assets that are called by subpaths? Or rather: why is the subpath route even calling a root asset?
Code for /routes/view/[id].svelte
:
<script context="module" lang="ts">
export const load = async ({ fetch, params }) => {
const id = params.id;
const url = `http://localhost:5000/company/${id}`;
const res: Response = await fetch(url);
const company = await res.json();
if (res.ok) {
return { props: {company} }
}
return { status: res.status }
}
</script>
<script lang="ts">
export let company: Company;
</script>
<h1>{company.name}</h1>
...
The /routes/view/index.svelte
file should not be a problem, that handles a simple redirection:
<script context="module" lang="ts">
export async function load() {
return {
status: 302, redirect: "/"
}
}
</script>
<script>
load();
</script>