diff --git a/.changeset/curvy-bugs-build.md b/.changeset/curvy-bugs-build.md new file mode 100644 index 000000000000..4fb178ce47cc --- /dev/null +++ b/.changeset/curvy-bugs-build.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: add trailing slash pathname when generating typed routes diff --git a/packages/kit/src/core/sync/write_non_ambient.js b/packages/kit/src/core/sync/write_non_ambient.js index df55a3cbee0d..c4161720879a 100644 --- a/packages/kit/src/core/sync/write_non_ambient.js +++ b/packages/kit/src/core/sync/write_non_ambient.js @@ -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} */ diff --git a/packages/kit/src/core/sync/write_types/test/app-types/+page.ts b/packages/kit/src/core/sync/write_types/test/app-types/+page.ts index 9d1f7ea39011..c47c696e7203 100644 --- a/packages/kit/src/core/sync/write_types/test/app-types/+page.ts +++ b/packages/kit/src/core/sync/write_types/test/app-types/+page.ts @@ -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';