Skip to content
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

fix(errors): NavigationCanceled with async components #3211

Merged
merged 2 commits into from
May 29, 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
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