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/every-kings-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: resolve_route prevent dropping a trailing slash of id
5 changes: 4 additions & 1 deletion packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ const basic_param_pattern = /\[(\[)?(\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;
*/
export function resolve_route(id, params) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I handle the trailing slash in resolve() function instead of inside of this function?

const segments = get_route_segments(id);
const has_id_trailing_slash = id != '/' && id.endsWith('/');

return (
'/' +
segments
Expand All @@ -262,7 +264,8 @@ export function resolve_route(id, params) {
})
)
.filter(Boolean)
.join('/')
.join('/') +
(has_id_trailing_slash ? '/' : '')
);
}

Expand Down
30 changes: 30 additions & 0 deletions packages/kit/src/utils/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,30 +278,60 @@ describe('resolve_route', () => {
params: { one: 'one', two: 'two' },
expected: '/blog/one/two'
},
{
route: '/blog/[one]/[two]/',
params: { one: 'one', two: 'two' },
expected: '/blog/one/two/'
},
{
route: '/blog/[one=matcher]/[...two]',
params: { one: 'one', two: 'two/three' },
expected: '/blog/one/two/three'
},
{
route: '/blog/[one=matcher]/[...two]/',
params: { one: 'one', two: 'two/three' },
expected: '/blog/one/two/three/'
},
{
route: '/blog/[one=matcher]/[[two]]',
params: { one: 'one' },
expected: '/blog/one'
},
{
route: '/blog/[one=matcher]/[[two]]/',
params: { one: 'one' },
expected: '/blog/one/'
},
{
route: '/blog/[one]/[two]-and-[three]',
params: { one: 'one', two: '2', three: '3' },
expected: '/blog/one/2-and-3'
},
{
route: '/blog/[one]/[two]-and-[three]/',
params: { one: 'one', two: '2', three: '3' },
expected: '/blog/one/2-and-3/'
},
{
route: '/blog/[...one]',
params: { one: '' },
expected: '/blog'
},
{
route: '/blog/[...one]/',
params: { one: '' },
expected: '/blog/'
},
{
route: '/blog/[one]/[...two]-not-three',
params: { one: 'one', two: 'two/2' },
expected: '/blog/one/two/2-not-three'
},
{
route: '/blog/[one]/[...two]-not-three/',
params: { one: 'one', two: 'two/2' },
expected: '/blog/one/two/2-not-three/'
}
];

Expand Down
Loading