From 62598b903a80ac9ece39171d0fb26a488a27e130 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 12 Jun 2020 11:27:48 +0200 Subject: [PATCH] fix(matcher): navigate to same as current location Closes #3216 --- src/history/base.js | 5 ++++- test/unit/specs/api.spec.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/history/base.js b/src/history/base.js index c31d4d496..4bfa0722b 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -137,10 +137,13 @@ export class History { } onAbort && onAbort(err) } + const lastRouteIndex = route.matched.length - 1 + const lastCurrentIndex = current.matched.length - 1 if ( isSameRoute(route, current) && // in the case the route map has been dynamically appended to - route.matched.length === current.matched.length + lastRouteIndex === lastCurrentIndex && + route.matched[lastRouteIndex] === current.matched[lastCurrentIndex] ) { this.ensureURL() return abort(createNavigationDuplicatedError(current, route)) diff --git a/test/unit/specs/api.spec.js b/test/unit/specs/api.spec.js index 8611b1987..2a31b2501 100644 --- a/test/unit/specs/api.spec.js +++ b/test/unit/specs/api.spec.js @@ -116,6 +116,23 @@ describe('router.addRoutes', () => { expect(components.length).toBe(1) expect(components[0].name).toBe('A') }) + + it('allows navigating to the same as current location', () => { + const router = new Router({ + routes: [ + { path: '/', component: {}}, + { path: '*', component: {}} + ] + }) + + router.push('/not-found') + + expect(router.currentRoute.params).toEqual({ pathMatch: '/not-found' }) + router.addRoutes([{ path: '/not-found', component: {}}]) + + // the navigation should have changed locations + expect(router.currentRoute.params).toEqual({}) + }) }) describe('router.push/replace', () => {