Skip to content

Commit 9d94d89

Browse files
committed
fix: preserve trailing slash when error boundary truncates branch
When a page's load function throws an error and the branch is truncated to the nearest error boundary, the page-level trailingSlash config is lost. This causes the URL to change (e.g. /test/ → /test). Default to 'ignore' instead of 'never' when an error is present, so the URL pathname stays unchanged. If a layout above the error boundary has its own trailingSlash config, it still overrides the default. Fixes #13516
1 parent 3804428 commit 9d94d89

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

packages/kit/src/runtime/client/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ async function initialize(result, target, hydrate) {
633633
*/
634634
function get_navigation_result_from_branch({ url, params, branch, status, error, route, form }) {
635635
/** @type {import('types').TrailingSlash} */
636-
let slash = 'never';
636+
let slash = error ? 'ignore' : 'never';
637637

638638
// if `paths.base === '/a/b/c`, then the root route is always `/a/b/c/`, regardless of
639639
// the `trailingSlash` route option, so that relative paths to JS and CSS work
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import { page } from '$app/state';
3+
</script>
4+
5+
<h1>Error: {page.error?.message}</h1>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { error } from '@sveltejs/kit';
2+
3+
export const trailingSlash = 'always';
4+
5+
export function load() {
6+
error(500, 'trailing slash error test');
7+
}

packages/kit/test/apps/basics/src/routes/routing/trailing-slash/error/always-error/+page.svelte

Whitespace-only changes.

packages/kit/test/apps/basics/test/cross-platform/client.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,15 @@ test.describe('Routing', () => {
11321132
expect(new URL(page.url()).pathname).toBe('/routing/trailing-slash/never');
11331133
await expect(page.locator('p')).toHaveText('/routing/trailing-slash/never');
11341134
});
1135+
1136+
test('trailing slash is preserved when error boundary truncates branch', async ({
1137+
page,
1138+
app
1139+
}) => {
1140+
await page.goto('/routing/trailing-slash');
1141+
await app.goto('/routing/trailing-slash/error/always-error/');
1142+
expect(new URL(page.url()).pathname).toBe('/routing/trailing-slash/error/always-error/');
1143+
});
11351144
});
11361145

11371146
test.describe('Shadow DOM', () => {

0 commit comments

Comments
 (0)