File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -137,10 +137,13 @@ export class History {
137137 }
138138 onAbort && onAbort ( err )
139139 }
140+ const lastRouteIndex = route . matched . length - 1
141+ const lastCurrentIndex = current . matched . length - 1
140142 if (
141143 isSameRoute ( route , current ) &&
142144 // in the case the route map has been dynamically appended to
143- route . matched . length === current . matched . length
145+ lastRouteIndex === lastCurrentIndex &&
146+ route . matched [ lastRouteIndex ] === current . matched [ lastCurrentIndex ]
144147 ) {
145148 this . ensureURL ( )
146149 return abort ( createNavigationDuplicatedError ( current , route ) )
Original file line number Diff line number Diff line change @@ -116,6 +116,23 @@ describe('router.addRoutes', () => {
116116 expect ( components . length ) . toBe ( 1 )
117117 expect ( components [ 0 ] . name ) . toBe ( 'A' )
118118 } )
119+
120+ it ( 'allows navigating to the same as current location' , ( ) => {
121+ const router = new Router ( {
122+ routes : [
123+ { path : '/' , component : { } } ,
124+ { path : '*' , component : { } }
125+ ]
126+ } )
127+
128+ router . push ( '/not-found' )
129+
130+ expect ( router . currentRoute . params ) . toEqual ( { pathMatch : '/not-found' } )
131+ router . addRoutes ( [ { path : '/not-found' , component : { } } ] )
132+
133+ // the navigation should have changed locations
134+ expect ( router . currentRoute . params ) . toEqual ( { } )
135+ } )
119136} )
120137
121138describe ( 'router.push/replace' , ( ) => {
You can’t perform that action at this time.
0 commit comments