File tree Expand file tree Collapse file tree
packages/router/src/unplugin/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2266,6 +2266,28 @@ describe('Tree', () => {
22662266 expect ( nested . children . has ( 'index' ) ) . toBe ( true )
22672267 expect ( nested . children . has ( 'other' ) ) . toBe ( true )
22682268 } )
2269+
2270+ it ( 'keeps _parent node when removing its last child' , ( ) => {
2271+ const tree = new PrefixTree ( RESOLVED_OPTIONS )
2272+ tree . insert ( 'users/_parent' , 'users/_parent.vue' )
2273+ tree . insert ( 'users/[id]' , 'users/[id].vue' )
2274+
2275+ tree . removeChild ( 'users/[id].vue' )
2276+
2277+ expect ( tree . children . get ( 'users' ) ?. value . components . get ( 'default' ) ) . toBe (
2278+ 'users/_parent.vue'
2279+ )
2280+ } )
2281+
2282+ it ( 'keeps _parent node when its last child deletes itself' , ( ) => {
2283+ const tree = new PrefixTree ( RESOLVED_OPTIONS )
2284+ tree . insert ( 'users/_parent' , 'users/_parent.vue' )
2285+ tree . insert ( 'users/[id]' , 'users/[id].vue' ) . delete ( )
2286+
2287+ expect ( tree . children . get ( 'users' ) ?. value . components . get ( 'default' ) ) . toBe (
2288+ 'users/_parent.vue'
2289+ )
2290+ } )
22692291 } )
22702292
22712293 describe ( 'Invalid param names in file names' , ( ) => {
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ export class TreeNode {
243243 protected deleteChild ( child : TreeNode ) : void {
244244 this . children . delete ( child . value . rawSegment )
245245 // recursively delete empty parents
246- if ( ! this . isRoot ( ) && ! this . isMatchable ( ) && this . children . size === 0 ) {
246+ if ( ! this . isRoot ( ) && ! this . hasComponents && this . children . size === 0 ) {
247247 this . delete ( )
248248 }
249249 }
You can’t perform that action at this time.
0 commit comments