Skip to content

Commit be39ca3

Browse files
authoredMay 29, 2020
fix(errors): NavigationCanceled with async components (#3211)
1 parent a0075ed commit be39ca3

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎src/history/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class History {
200200
const queue = enterGuards.concat(this.router.resolveHooks)
201201
runQueue(queue, iterator, () => {
202202
if (this.pending !== route) {
203-
return abort()
203+
return abort(createNavigationCancelledError(current, route))
204204
}
205205
this.pending = null
206206
onComplete(route)

‎test/unit/specs/error-handling.spec.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('error handling', () => {
99
const router = new VueRouter()
1010
const err = new Error('foo')
1111
router.beforeEach(() => { throw err })
12-
router.onError(() => {})
12+
router.onError(() => { })
1313

1414
const onReady = jasmine.createSpy('ready')
1515
const onError = jasmine.createSpy('error')
@@ -65,6 +65,26 @@ describe('error handling', () => {
6565
router.push('/')
6666
})
6767

68+
it('NavigationCancelled error for nested async navigation', (done) => {
69+
const component = {
70+
template: `<img />`,
71+
beforeRouteEnter (to, from, next) {
72+
setTimeout(() => next(), 100)
73+
}
74+
}
75+
const router = new VueRouter({
76+
routes: [
77+
{ path: '/a', component }
78+
]
79+
})
80+
81+
router.push('/a').catch(err => {
82+
expect(err.type).toBe(NavigationFailureType.cancelled)
83+
done()
84+
})
85+
router.push('/')
86+
})
87+
6888
it('NavigationRedirected error', done => {
6989
const router = new VueRouter()
7090

@@ -105,7 +125,7 @@ describe('error handling', () => {
105125
})
106126

107127
router.onError(spy1)
108-
router.onReady(() => {}, spy2)
128+
router.onReady(() => { }, spy2)
109129

110130
router.push('/').catch(spy3).finally(() => {
111131
expect(spy1).toHaveBeenCalledWith(err)

0 commit comments

Comments
 (0)