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
8 changes: 7 additions & 1 deletion packages/router-core/src/new-process-route-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ function parseSegments<TRouteLike extends RouteLike>(
// but if there is *also* a layout route at this path, save it as notFound
// we can use it when fuzzy matching to display the NotFound component in the layout route
if (!isIndex) node.notFound = route
if (!node.route || (!node.isIndex && isIndex)) node.route = route
// does the new route take precedence over an existing one?
// yes if previous is not an index route and new one is an index route
if (!node.route || (!node.isIndex && isIndex)) {
node.route = route
// when replacing, replace all attributes that are route-specific (`fullPath` only at the moment)
node.fullPath = route.fullPath ?? route.from
}
node.isIndex ||= isIndex
}
}
Expand Down
31 changes: 31 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 @@ -831,6 +831,37 @@ describe('findRouteMatch', () => {
expect(result?.params).toEqual({ '**': decoded })
})
})
describe('edge-cases', () => {
it('#6012: optional index at root with param extraction', () => {
const tree = {
id: '__root__',
fullPath: '/',
path: '/',
isRoot: true,
options: {},
children: [
{
id: '/{-$year}/{-$month}/{-$day}',
fullPath: '/{-$year}/{-$month}/{-$day}',
path: '{-$year}/{-$month}/{-$day}',
isRoot: false,
options: {},
},
{
id: '/_pathless/{-$language}/',
fullPath: '/{-$language}/',
path: '{-$language}/',
isRoot: false,
options: {},
},
],
}
const { processedTree } = processRouteTree(tree)
const result = findRouteMatch(`/sv`, processedTree)
expect(result?.route.id).toBe('/_pathless/{-$language}/')
expect(result?.params).toEqual({ language: 'sv' })
})
})
})
})

Expand Down
Loading