Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-bugs-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: add trailing slash pathname when generating typed routes
13 changes: 12 additions & 1 deletion packages/kit/src/core/sync/write_non_ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ function generate_app_types(manifest_data) {
dynamic_routes.push(route_type);

const pathname = remove_group_segments(route.id);
pathnames.add(`\`${replace_required_params(replace_optional_params(pathname))}\` & {}`);
const replaced_pathname = replace_required_params(replace_optional_params(pathname));
pathnames.add(`\`${replaced_pathname}\` & {}`);

if (pathname !== '/') {
// Support trailing slash
pathnames.add(`\`${replaced_pathname + '/'}\` & {}`);
}
} else {
const pathname = remove_group_segments(route.id);
pathnames.add(s(pathname));

if (pathname !== '/') {
// Support trailing slash
pathnames.add(s(pathname + '/'));
}
}

/** @type {Map<string, boolean>} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ declare let pathname: Pathname;
pathname = '/nope';
pathname = '/foo';
pathname = '/foo/1/2';
pathname = '/foo/';
pathname = '/foo/1/2/';

// Test layout groups
pathname = '/path-a';
pathname = '/path-a/';
// @ts-expect-error layout group names are NOT part of the pathname type
pathname = '/(group)/path-a';

Expand Down