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
6 changes: 6 additions & 0 deletions packages/router-core/src/new-process-route-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ function getNodeMatch<T extends RouteLike>(
}
}

if (bestMatch && wildcardMatch) {
return isFrameMoreSpecific(wildcardMatch, bestMatch)
? bestMatch
: wildcardMatch
}

if (bestMatch) return bestMatch

if (wildcardMatch) return wildcardMatch
Expand Down
24 changes: 24 additions & 0 deletions packages/router-core/tests/new-process-route-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,30 @@ describe('findRouteMatch', () => {
expect(res?.route.id).toBe('/a/b/$')
expect(res?.params).toEqual({ _splat: 'foo', '*': 'foo' })
})
describe('edge-case #5969: trailing empty wildcard should match', () => {
it('basic', () => {
const tree = makeTree(['/a/$'])
expect(findRouteMatch('/a/', tree)?.route.id).toBe('/a/$')
expect(findRouteMatch('/a', tree)?.route.id).toBe('/a/$')
})
it('with layout route', () => {
const tree = makeTree(['/a', '/a/$'])
expect(findRouteMatch('/a/', tree)?.route.id).toBe('/a/$')
expect(findRouteMatch('/a', tree)?.route.id).toBe('/a/$')
})
it('with index route (should not match)', () => {
const tree = makeTree(['/a/', '/a/$'])
expect(findRouteMatch('/a/', tree)?.route.id).toBe('/a/')
expect(findRouteMatch('/a', tree)?.route.id).toBe('/a/')
})
it('edge-case: deeper index route through skipped optional segments (should not match)', () => {
const tree = makeTree(['/{-$foo}/{-$bar}/a/', '/a/$'])
expect(findRouteMatch('/a/', tree)?.route.id).toBe(
'/{-$foo}/{-$bar}/a/',
)
expect(findRouteMatch('/a', tree)?.route.id).toBe('/{-$foo}/{-$bar}/a/')
})
})
})

describe('nested routes', () => {
Expand Down
Loading