File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed
packages/router/src/unplugin Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -827,6 +827,39 @@ describe('generateRouteNamedMap', () => {
827827 ` )
828828 } )
829829
830+ it ( 'excludes _parent routes from route map after setCustomRouteBlock' , ( ) => {
831+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
832+ tree . insert ( 'nested/_parent' , 'nested/_parent.vue' )
833+ tree . insert ( 'nested/index' , 'nested/index.vue' )
834+ tree . insert ( 'nested/other' , 'nested/other.vue' )
835+
836+ // Simulate what context.ts:writeRouteInfoToNode does
837+ const nestedNode = tree . children . get ( 'nested' ) !
838+ nestedNode . setCustomRouteBlock ( 'nested/_parent.vue' , { } )
839+
840+ // Should NOT contain '/nested' entry — _parent convention override persists
841+ expect (
842+ formatExports ( generateRouteNamedMap ( tree , DEFAULT_OPTIONS , new Map ( ) ) )
843+ ) . toMatchInlineSnapshot ( `
844+ "export interface RouteNamedMap {
845+ '/nested/': RouteRecordInfo<
846+ '/nested/',
847+ '/nested',
848+ Record<never, never>,
849+ Record<never, never>,
850+ | never
851+ >,
852+ '/nested/other': RouteRecordInfo<
853+ '/nested/other',
854+ '/nested/other',
855+ Record<never, never>,
856+ Record<never, never>,
857+ | never
858+ >,
859+ }"
860+ ` )
861+ } )
862+
830863 it ( 'excludes routes with empty names from route map' , ( ) => {
831864 const tree = new PrefixTree ( DEFAULT_OPTIONS )
832865 tree . insert ( 'parent' , 'parent.vue' )
Original file line number Diff line number Diff line change 11import { type ResolvedOptions } from '../options'
22import {
3+ CONVENTION_OVERRIDE_NAME ,
34 createTreeNodeValue ,
45 escapeRegex ,
56 type TreeNodeValueOptions ,
@@ -93,8 +94,9 @@ export class TreeNode {
9394 // _parent.vue is set on the current node to handle nesting
9495 // similar to nested.vue when we have a folder nested/
9596 if ( segment === '_parent' && ! tail ) {
96- // a parent can't be matched
97- this . value . setOverride ( filePath , { name : false } )
97+ // a parent can't be matched, equivalent to name: false unless
98+ // overridden by the user
99+ this . value . setOverride ( CONVENTION_OVERRIDE_NAME , { name : false } )
98100 this . value . components . set ( viewName , filePath )
99101 return this
100102 }
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ export interface RouteRecordOverrideQueryParamOptions extends CustomRouteBlockQu
3939
4040export type SubSegment = string | TreePathParam
4141
42+ // internal name used for overrides set by file-based conventions (e.g. _parent)
43+ export const CONVENTION_OVERRIDE_NAME = '@@convention'
4244// internal name used for overrides done by the user at build time
4345export const EDITS_OVERRIDE_NAME = '@@edits'
4446
@@ -196,9 +198,10 @@ class _TreeNodeValueBase {
196198 . sort ( ( [ nameA ] , [ nameB ] ) =>
197199 nameA === nameB
198200 ? 0
199- : // EDITS_OVERRIDE_NAME should always be last
200- nameA !== EDITS_OVERRIDE_NAME &&
201- ( nameA < nameB || nameB === EDITS_OVERRIDE_NAME )
201+ : // CONVENTION_OVERRIDE_NAME should always be first, EDITS_OVERRIDE_NAME should always be last
202+ nameA === CONVENTION_OVERRIDE_NAME ||
203+ ( nameA !== EDITS_OVERRIDE_NAME &&
204+ ( nameA < nameB || nameB === EDITS_OVERRIDE_NAME ) )
202205 ? - 1
203206 : 1
204207 )
You can’t perform that action at this time.
0 commit comments