Skip to content

Commit ece8d3d

Browse files
committed
fix: splat at root
1 parent ecd1303 commit ece8d3d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,27 @@ describe('MatcherPatternPathDynamic', () => {
272272
expect(pattern.build({ pathMatch: '124/b' })).toBe('/teams/124/b')
273273
})
274274

275+
it('splat param without prefix', () => {
276+
const pattern = new MatcherPatternPathDynamic(
277+
/^\/(.*)$/,
278+
{
279+
pathMatch: [],
280+
},
281+
[0],
282+
null
283+
)
284+
expect(pattern.match('/')).toEqual({ pathMatch: '' })
285+
expect(pattern.match('/123/b')).toEqual({ pathMatch: '123/b' })
286+
expect(pattern.match('/anything/goes/here')).toEqual({
287+
pathMatch: 'anything/goes/here',
288+
})
289+
290+
expect(pattern.build({ pathMatch: null })).toBe('/')
291+
expect(pattern.build({ pathMatch: '' })).toBe('/')
292+
expect(pattern.build({ pathMatch: '124' })).toBe('/124')
293+
expect(pattern.build({ pathMatch: '124/b' })).toBe('/124/b')
294+
})
295+
275296
it('repeatable optional param', () => {
276297
const pattern = new MatcherPatternPathDynamic(
277298
/^\/teams(?:\/(.+?))?\/b$/i,

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class MatcherPatternPathDynamic<
283283
* no sense to build a path it cannot match.
284284
*/
285285
return this.trailingSlash == null
286-
? path + (!value ? '/' : '')
286+
? path + (!value && path.at(-1) !== '/' ? '/' : '')
287287
: path.replace(RE_TRAILING_SLASHES, this.trailingSlash ? '/' : '')
288288
}
289289
}

0 commit comments

Comments
 (0)