File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,17 @@ export class History {
77
77
onComplete ? : Function ,
78
78
onAbort ? : Function
79
79
) {
80
- const route = this . router . match ( location , this . current )
80
+ let route
81
+ try {
82
+ route = this . router . match ( location , this . current )
83
+ } catch ( e ) {
84
+ this . errorCbs . forEach ( cb => {
85
+ cb ( e )
86
+ } )
87
+ // Exception should still be thrown
88
+ // https://github.com/vuejs/vue-router/issues/3201
89
+ throw e
90
+ }
81
91
this . confirmTransition (
82
92
route ,
83
93
( ) => {
Original file line number Diff line number Diff line change @@ -183,4 +183,33 @@ describe('error handling', () => {
183
183
done ( )
184
184
} )
185
185
} )
186
+
187
+ it ( 'should trigger onError when an exception is thrown' , done => {
188
+ const config = [ {
189
+ path : '/oldpath/:part' ,
190
+ redirect : ( to ) => {
191
+ if ( to . ooopsmistake . part ) {
192
+ return `/newpath/${ to . params . part } `
193
+ }
194
+ return '/newpath/'
195
+ }
196
+ } ]
197
+
198
+ const router = new VueRouter ( {
199
+ routes : config
200
+ } )
201
+
202
+ const onError = jasmine . createSpy ( 'onError' )
203
+ router . onError ( onError )
204
+ const pushCatch = jasmine . createSpy ( 'pushCatch' )
205
+
206
+ router
207
+ . push ( '/oldpath/test' )
208
+ . catch ( pushCatch )
209
+ . finally ( ( ) => {
210
+ expect ( pushCatch ) . toHaveBeenCalled ( )
211
+ expect ( onError ) . toHaveBeenCalled ( )
212
+ done ( )
213
+ } )
214
+ } )
186
215
} )
You can’t perform that action at this time.
0 commit comments