Skip to content

Commit 62598b9

Browse files
committed
fix(matcher): navigate to same as current location
Closes #3216
1 parent 9ff90bd commit 62598b9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/history/base.js

+4-1
Original file line numberDiff line numberDiff 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))

test/unit/specs/api.spec.js

+17
Original file line numberDiff line numberDiff 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

121138
describe('router.push/replace', () => {

0 commit comments

Comments
 (0)