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
1 change: 1 addition & 0 deletions packages/router-core/src/new-process-route-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ function extractParams<T extends RouteLike>(
} else if (node.kind === SEGMENT_TYPE_OPTIONAL_PARAM) {
if (leaf.skipped & (1 << nodeIndex)) {
partIndex-- // stay on the same part
pathIndex = currentPathIndex - 1 // undo pathIndex advancement; -1 to account for loop increment
continue
}
nodeParts ??= leaf.node.fullPath.split('/')
Expand Down
22 changes: 22 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 @@ -864,6 +864,28 @@ describe('findRouteMatch', () => {
expect(result?.route.id).toBe('/_pathless/{-$language}/')
expect(result?.rawParams).toEqual({ language: 'sv' })
})
it('skipped optional, ends with wildcard', () => {
const tree = {
id: '__root__',
fullPath: '/',
path: '/',
isRoot: true,
options: {},
children: [
{
id: '/{-$foo}/bar/$',
fullPath: '/{-$foo}/bar/$',
path: '{-$foo}/bar/$',
isRoot: false,
options: {},
},
],
}
const { processedTree } = processRouteTree(tree)
const result = findRouteMatch(`/bar/rest`, processedTree)
expect(result?.route.id).toBe('/{-$foo}/bar/$')
expect(result?.rawParams).toEqual({ '*': 'rest', _splat: 'rest' })
})
})
})
describe('pathless routes', () => {
Expand Down
Loading