Skip to content

Commit 26af63f

Browse files
committed
fix(AbstractHistory): Fix router.back in abstract mode
Fix abstract mode's router.back() when 2 consecutive same routes appear in the history stack array fix vuejs#2607
1 parent 8ac478f commit 26af63f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/history/abstract.js

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class AbstractHistory extends History {
3737
this.confirmTransition(route, () => {
3838
this.index = targetIndex
3939
this.updateRoute(route)
40+
}, (err) => {
41+
if (err === 'SAME_ROUTE') {
42+
this.index = targetIndex
43+
}
4044
})
4145
}
4246

src/history/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class History {
103103
route.matched.length === current.matched.length
104104
) {
105105
this.ensureURL()
106-
return abort()
106+
return abort('SAME_ROUTE')
107107
}
108108

109109
const {

test/unit/specs/node.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,21 @@ describe('Usage in Node', () => {
3535
expect(router.getMatchedComponents('/')).toEqual([Foo])
3636
expect(router.getMatchedComponents('/bar/baz')).toEqual([Bar, Baz])
3737
})
38+
39+
it('should navigate through history with same consecutive routes in history stack', () => {
40+
const router = new VueRouter({
41+
routes: [
42+
{ path: '/', component: { name: 'foo' }},
43+
{ path: '/bar', component: { name: 'bar' }}
44+
]
45+
})
46+
router.push('/')
47+
router.push('/bar')
48+
router.push('/')
49+
router.replace('/bar')
50+
router.back()
51+
expect(router.history.current.path).toBe('/bar')
52+
router.back()
53+
expect(router.history.current.path).toBe('/')
54+
})
3855
})

0 commit comments

Comments
 (0)