File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,18 +69,20 @@ export default class RouteNode {
6969 originalRoute = route ;
7070 route = new RouteNode ( route . name , route . path , route . children ) ;
7171 }
72- // Check duplicated routes
73- if ( this . children . map ( child => child . name ) . indexOf ( route . name ) !== - 1 ) {
74- throw new Error ( `Alias "${ route . name } " is already defined in route node` ) ;
75- }
76- // Check duplicated paths
77- if ( this . children . map ( child => child . path ) . indexOf ( route . path ) !== - 1 ) {
78- throw new Error ( `Path "${ route . path } " is already defined in route node` ) ;
79- }
8072
8173 let names = route . name . split ( '.' ) ;
8274
8375 if ( names . length === 1 ) {
76+ // Check duplicated routes
77+ if ( this . children . map ( child => child . name ) . indexOf ( route . name ) !== - 1 ) {
78+ throw new Error ( `Alias "${ route . name } " is already defined in route node` ) ;
79+ }
80+
81+ // Check duplicated paths
82+ if ( this . children . map ( child => child . path ) . indexOf ( route . path ) !== - 1 ) {
83+ throw new Error ( `Path "${ route . path } " is already defined in route node` ) ;
84+ }
85+
8486 this . children . push ( route ) ;
8587 // Push greedy spats to the bottom of the pile
8688 this . children . sort ( ( left , right ) => {
Original file line number Diff line number Diff line change @@ -95,6 +95,14 @@ describe('RouteNode', function () {
9595 ( function ( ) {
9696 root . add ( { name : 'profile' , path : '/home' } )
9797 } ) . should . throw ( 'Path "/home" is already defined in route node' ) ;
98+
99+ ( function ( ) {
100+ root . add ( { name : 'home.profile' , path : '/home' } )
101+ } ) . should . not . throw ( ) ;
102+
103+ ( function ( ) {
104+ root . add ( { name : 'home.profile' , path : '/profile' } )
105+ } ) . should . throw ( ) ;
98106 } ) ;
99107
100108 it ( 'should throw an error when trying to add a route which parent doesn\'t exist' , function ( ) {
You can’t perform that action at this time.
0 commit comments