Skip to content

Commit

Permalink
fix(errors): NavigationCanceled with async components (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed May 29, 2020
1 parent a0075ed commit be39ca3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class History {
const queue = enterGuards.concat(this.router.resolveHooks)
runQueue(queue, iterator, () => {
if (this.pending !== route) {
return abort()
return abort(createNavigationCancelledError(current, route))
}
this.pending = null
onComplete(route)
Expand Down
24 changes: 22 additions & 2 deletions test/unit/specs/error-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('error handling', () => {
const router = new VueRouter()
const err = new Error('foo')
router.beforeEach(() => { throw err })
router.onError(() => {})
router.onError(() => { })

const onReady = jasmine.createSpy('ready')
const onError = jasmine.createSpy('error')
Expand Down Expand Up @@ -65,6 +65,26 @@ describe('error handling', () => {
router.push('/')
})

it('NavigationCancelled error for nested async navigation', (done) => {
const component = {
template: `<img />`,
beforeRouteEnter (to, from, next) {
setTimeout(() => next(), 100)
}
}
const router = new VueRouter({
routes: [
{ path: '/a', component }
]
})

router.push('/a').catch(err => {
expect(err.type).toBe(NavigationFailureType.cancelled)
done()
})
router.push('/')
})

it('NavigationRedirected error', done => {
const router = new VueRouter()

Expand Down Expand Up @@ -105,7 +125,7 @@ describe('error handling', () => {
})

router.onError(spy1)
router.onReady(() => {}, spy2)
router.onReady(() => { }, spy2)

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

0 comments on commit be39ca3

Please sign in to comment.