Skip to content

Commit d8f9198

Browse files
fix: add support for trailing slashes in typed routes (#14065)
* fix: add support for trailing slashes in typed routes * fix merge --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 69b6384 commit d8f9198

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/curvy-bugs-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: add trailing slash pathname when generating typed routes

packages/kit/src/core/sync/write_non_ambient.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,21 @@ function generate_app_types(manifest_data) {
6666
dynamic_routes.push(route_type);
6767

6868
const pathname = remove_group_segments(route.id);
69-
pathnames.add(`\`${replace_required_params(replace_optional_params(pathname))}\` & {}`);
69+
const replaced_pathname = replace_required_params(replace_optional_params(pathname));
70+
pathnames.add(`\`${replaced_pathname}\` & {}`);
71+
72+
if (pathname !== '/') {
73+
// Support trailing slash
74+
pathnames.add(`\`${replaced_pathname + '/'}\` & {}`);
75+
}
7076
} else {
7177
const pathname = remove_group_segments(route.id);
7278
pathnames.add(s(pathname));
79+
80+
if (pathname !== '/') {
81+
// Support trailing slash
82+
pathnames.add(s(pathname + '/'));
83+
}
7384
}
7485

7586
/** @type {Map<string, boolean>} */

packages/kit/src/core/sync/write_types/test/app-types/+page.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ declare let pathname: Pathname;
2626
pathname = '/nope';
2727
pathname = '/foo';
2828
pathname = '/foo/1/2';
29+
pathname = '/foo/';
30+
pathname = '/foo/1/2/';
2931

3032
// Test layout groups
3133
pathname = '/path-a';
34+
pathname = '/path-a/';
3235
// @ts-expect-error layout group names are NOT part of the pathname type
3336
pathname = '/(group)/path-a';
3437

0 commit comments

Comments
 (0)