URLs not reflecting base path in SvelteKit + @sveltejs/adapter-static setup

100 Views Asked by At

I am building a static website using SvelteKit. It's a static site (I'm using @sveltejs/adapter-static) and I've set a base path to "example" in the svelte.config.js file. When I use pnpm run build to build the site (forcing prerender using export const prerender = true), all urls are rendered like this: ./page, but I think they all should be something like /example/page.

This leads to some very strange behavior. When clicking on a link, the url of the page sometimes gets added to the current url (resulting in things like /example/page_1/page_2/), leading to a 404. But the strange part is that this doesn't always happen and I can't find any logic in it.

The links are in the +layout.svelte file, but the same happens when they are in a component, that's used in the layout. If the links are directly inside of a normal page, this all doesn't happen.

This is the content of the +layout.svelte file:

<script>
    import { base } from '$app/paths';
</script>

<slot />
<p>Go to <a href="{base}/">home</a>, <a href="{base}/page_1">page 1</a> or <a href="{base}/page_2">page 2</a>.</p>

This is the +layout.js file:

export const prerender = true

And this is the svelte.config.js file:

import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter(),
        paths: {
            base: '/examle-url'
        }
    }
};

export default config;

Aside from that I'm using the standard files that are provided after the pnpm create svelte@latest command.

What am I doing wrong that causes the wrong build? Or could this be a bug?

0

There are 0 best solutions below