Skip to content

Commit

Permalink
fix(AbstractHistory): Fix router.back in abstract mode
Browse files Browse the repository at this point in the history
Fix abstract mode's router.back() when 2 consecutive same routes appear in the history stack array

fix #2607
  • Loading branch information
Domino9697 committed May 17, 2019
1 parent 8ac478f commit 26af63f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/history/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class AbstractHistory extends History {
this.confirmTransition(route, () => {
this.index = targetIndex
this.updateRoute(route)
}, (err) => {
if (err === 'SAME_ROUTE') {
this.index = targetIndex
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class History {
route.matched.length === current.matched.length
) {
this.ensureURL()
return abort()
return abort('SAME_ROUTE')
}

const {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/specs/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,21 @@ describe('Usage in Node', () => {
expect(router.getMatchedComponents('/')).toEqual([Foo])
expect(router.getMatchedComponents('/bar/baz')).toEqual([Bar, Baz])
})

it('should navigate through history with same consecutive routes in history stack', () => {
const router = new VueRouter({
routes: [
{ path: '/', component: { name: 'foo' }},
{ path: '/bar', component: { name: 'bar' }}
]
})
router.push('/')
router.push('/bar')
router.push('/')
router.replace('/bar')
router.back()
expect(router.history.current.path).toBe('/bar')
router.back()
expect(router.history.current.path).toBe('/')
})
})

0 comments on commit 26af63f

Please sign in to comment.