Skip to content

fix(matcher): navigate to same as current location #3228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 17 additions & 0 deletions test/unit/specs/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down