File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1076,5 +1076,22 @@ describe('Router', () => {
1076
1076
name : 'Param' ,
1077
1077
} )
1078
1078
} )
1079
+
1080
+ it ( 'warns when the parent route is missing' , async ( ) => {
1081
+ const { router } = await newRouter ( )
1082
+ router . addRoute ( 'parent-route' , {
1083
+ path : '/p' ,
1084
+ component : components . Foo ,
1085
+ } )
1086
+ expect (
1087
+ 'Parent route "parent-route" not found when adding child route'
1088
+ ) . toHaveBeenWarned ( )
1089
+ } )
1090
+
1091
+ it ( 'warns when removing a missing route' , async ( ) => {
1092
+ const { router } = await newRouter ( )
1093
+ router . removeRoute ( 'route-name' )
1094
+ expect ( 'Cannot remove non-existent route "route-name"' ) . toHaveBeenWarned ( )
1095
+ } )
1079
1096
} )
1080
1097
} )
Original file line number Diff line number Diff line change @@ -397,6 +397,14 @@ export function createRouter(options: RouterOptions): Router {
397
397
let record : RouteRecordRaw
398
398
if ( isRouteName ( parentOrRoute ) ) {
399
399
parent = matcher . getRecordMatcher ( parentOrRoute )
400
+ if ( __DEV__ && ! parent ) {
401
+ warn (
402
+ `Parent route "${ String (
403
+ parentOrRoute
404
+ ) } " not found when adding child route`,
405
+ route
406
+ )
407
+ }
400
408
record = route !
401
409
} else {
402
410
record = parentOrRoute
You can’t perform that action at this time.
0 commit comments