From c71e953998977ad3c3fc2387842d68d62552a400 Mon Sep 17 00:00:00 2001 From: Bowen Date: Fri, 29 May 2020 10:48:24 +0800 Subject: [PATCH 1/2] fix: should has a canceled error as well --- src/history/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/history/base.js b/src/history/base.js index ce98f18e9..4eb85a55e 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -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) From 82a19d19403463e259bb738315817c1180fb773f Mon Sep 17 00:00:00 2001 From: Bowen Liu Date: Fri, 29 May 2020 17:34:01 +0800 Subject: [PATCH 2/2] test(errors): cancelled error for nested async navigation --- test/unit/specs/error-handling.spec.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/unit/specs/error-handling.spec.js b/test/unit/specs/error-handling.spec.js index 8d41bca18..d73a89d95 100644 --- a/test/unit/specs/error-handling.spec.js +++ b/test/unit/specs/error-handling.spec.js @@ -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') @@ -65,6 +65,26 @@ describe('error handling', () => { router.push('/') }) + it('NavigationCancelled error for nested async navigation', (done) => { + const component = { + template: ``, + 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() @@ -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)