Skip to content

Commit 1dfccf8

Browse files
committed
fix: avoid route entry in map for _parent
1 parent d776470 commit 1dfccf8

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

packages/router/src/unplugin/codegen/generateRouteMap.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,66 @@ describe('generateRouteNamedMap', () => {
739739
)
740740
})
741741

742+
it('excludes _parent routes from route map', () => {
743+
const tree = new PrefixTree(DEFAULT_OPTIONS)
744+
tree.insert('nested/_parent', 'nested/_parent.vue')
745+
tree.insert('nested/index', 'nested/index.vue')
746+
tree.insert('nested/other', 'nested/other.vue')
747+
748+
// _parent route creates a parent component but is non-matchable (name: false)
749+
// so it should NOT appear in the RouteNamedMap
750+
expect(
751+
formatExports(generateRouteNamedMap(tree, DEFAULT_OPTIONS, new Map()))
752+
).toMatchInlineSnapshot(`
753+
"export interface RouteNamedMap {
754+
'/nested/': RouteRecordInfo<
755+
'/nested/',
756+
'/nested',
757+
Record<never, never>,
758+
Record<never, never>,
759+
| never
760+
>,
761+
'/nested/other': RouteRecordInfo<
762+
'/nested/other',
763+
'/nested/other',
764+
Record<never, never>,
765+
Record<never, never>,
766+
| never
767+
>,
768+
}"
769+
`)
770+
})
771+
772+
it('excludes _parent routes without index from children union', () => {
773+
const tree = new PrefixTree(DEFAULT_OPTIONS)
774+
tree.insert('nested/_parent', 'nested/_parent.vue')
775+
tree.insert('nested/child', 'nested/child.vue')
776+
tree.insert('nested/other', 'nested/other.vue')
777+
778+
// _parent is non-matchable so it doesn't appear in the map
779+
// and its children (child, other) should not list _parent in their unions
780+
expect(
781+
formatExports(generateRouteNamedMap(tree, DEFAULT_OPTIONS, new Map()))
782+
).toMatchInlineSnapshot(`
783+
"export interface RouteNamedMap {
784+
'/nested/child': RouteRecordInfo<
785+
'/nested/child',
786+
'/nested/child',
787+
Record<never, never>,
788+
Record<never, never>,
789+
| never
790+
>,
791+
'/nested/other': RouteRecordInfo<
792+
'/nested/other',
793+
'/nested/other',
794+
Record<never, never>,
795+
Record<never, never>,
796+
| never
797+
>,
798+
}"
799+
`)
800+
})
801+
742802
it('excludes routes with empty names from route map', () => {
743803
const tree = new PrefixTree(DEFAULT_OPTIONS)
744804
tree.insert('parent', 'parent.vue')

packages/router/src/unplugin/core/tree.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ export class TreeNode {
157157
filePath: string,
158158
routeBlock: CustomRouteBlock | undefined
159159
) {
160-
this.value.setOverride(filePath, routeBlock)
160+
// Use mergeOverride to preserve existing override properties (e.g. name: false for _parent routes)
161+
if (routeBlock) {
162+
this.value.mergeOverride(filePath, routeBlock)
163+
}
161164
}
162165

163166
/**

0 commit comments

Comments
 (0)