diff --git a/src/history/base.js b/src/history/base.js index a070f27c6..7425df13a 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -78,6 +78,7 @@ export class History { onAbort?: Function ) { let route + // catch redirect option https://github.com/vuejs/vue-router/issues/3201 try { route = this.router.match(location, this.current) } catch (e) { @@ -85,7 +86,6 @@ export class History { cb(e) }) // Exception should still be thrown - // https://github.com/vuejs/vue-router/issues/3201 throw e } this.confirmTransition( diff --git a/test/unit/specs/error-handling.spec.js b/test/unit/specs/error-handling.spec.js index d8784aa5e..003dad6f9 100644 --- a/test/unit/specs/error-handling.spec.js +++ b/test/unit/specs/error-handling.spec.js @@ -184,14 +184,12 @@ describe('error handling', () => { }) }) - it('should trigger onError when an exception is thrown', done => { + it('should trigger onError if error is thrown inside redirect option', done => { + const error = new Error('foo') const config = [{ path: '/oldpath/:part', redirect: (to) => { - if (to.ooopsmistake.part) { - return `/newpath/${to.params.part}` - } - return '/newpath/' + throw error } }] @@ -207,8 +205,8 @@ describe('error handling', () => { .push('/oldpath/test') .catch(pushCatch) .finally(() => { - expect(pushCatch).toHaveBeenCalled() - expect(onError).toHaveBeenCalled() + expect(pushCatch).toHaveBeenCalledWith(error) + expect(onError).toHaveBeenCalledWith(error) done() }) })