Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ export function write_all_types(config, 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 !== '/') {
Copy link
Contributor Author

@yuki0418 yuki0418 Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to add trailing slash only when export const trailingSlash = 'always'; is in a file.
But I couldn't find a way to check it.

// Support trailing slash
pathnames.add(`\`${replaced_pathname + '/'}\` & {}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just add a trailing slash to type Pathname because user would not enter Router Id in href.
Sorry if I'm wrong.

}
} 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
Loading