File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ class Router {
61
61
this . _currentTransition = null
62
62
this . _previousTransition = null
63
63
this . _notFoundHandler = null
64
+ this . _notFoundRedirect = null
64
65
this . _beforeEachHooks = [ ]
65
66
this . _afterEachHooks = [ ]
66
67
@@ -315,7 +316,11 @@ class Router {
315
316
*/
316
317
317
318
_addRedirect ( path , redirectPath ) {
318
- this . _addGuard ( path , redirectPath , this . replace )
319
+ if ( path === '*' ) {
320
+ this . _notFoundRedirect = redirectPath
321
+ } else {
322
+ this . _addGuard ( path , redirectPath , this . replace )
323
+ }
319
324
}
320
325
321
326
/**
@@ -363,6 +368,12 @@ class Router {
363
368
if ( matched ) {
364
369
matched [ 0 ] . handler ( matched [ 0 ] , matched . queryParams )
365
370
return true
371
+ } else if ( this . _notFoundRedirect ) {
372
+ matched = this . _recognizer . recognize ( path )
373
+ if ( ! matched ) {
374
+ this . replace ( this . _notFoundRedirect )
375
+ return true
376
+ }
366
377
}
367
378
}
368
379
Original file line number Diff line number Diff line change @@ -529,15 +529,17 @@ describe('Core', function () {
529
529
} )
530
530
router . redirect ( {
531
531
'/whatever' : '/a/b' ,
532
- '/ok' : '/a/c'
532
+ '/ok' : '/a/c' ,
533
+ '*' : '/a/b'
533
534
} )
534
535
var App = Vue . extend ( {
535
536
template : '<div><router-view></router-view></div>'
536
537
} )
537
538
router . start ( App , el )
538
539
assertRoutes ( [
539
540
[ '/whatever' , 'hello' ] ,
540
- [ '/ok?msg=world' , 'world' ]
541
+ [ '/ok?msg=world' , 'world' ] ,
542
+ [ '/fesfsefsef' , 'hello' ]
541
543
] , done )
542
544
} )
543
545
You can’t perform that action at this time.
0 commit comments