diff --git a/.changeset/lovely-plums-move.md b/.changeset/lovely-plums-move.md new file mode 100644 index 000000000000..e9e96dc55ad9 --- /dev/null +++ b/.changeset/lovely-plums-move.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +fix: correctly handle trailing slash redirect when navigating from the root page diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 6db0ec702efc..1c5e86cd19a6 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -660,10 +660,10 @@ export function create_client(app, target) { server: server_data_node, universal: node.universal?.load ? { type: 'data', data, uses } : null, data: data ?? server_data_node?.data ?? null, - // if `paths.base === '/a/b/c`, then the root route is `/a/b/c/`, - // regardless of the `trailingSlash` route option + // if `paths.base === '/a/b/c`, then the root route is always `/a/b/c/`, regardless of + // the `trailingSlash` route option, so that relative paths to JS and CSS work slash: - url.pathname === base || url.pathname === base + '/' + base && (url.pathname === base || url.pathname === base + '/') ? 'always' : node.universal?.trailingSlash ?? server_data_node?.slash }; diff --git a/packages/kit/test/apps/basics/src/routes/+page.svelte b/packages/kit/test/apps/basics/src/routes/+page.svelte index a63bddab544e..f4e941a22080 100644 --- a/packages/kit/test/apps/basics/src/routes/+page.svelte +++ b/packages/kit/test/apps/basics/src/routes/+page.svelte @@ -6,3 +6,7 @@