@@ -32,20 +32,21 @@ export class History {
32
32
this . cb = cb
33
33
}
34
34
35
- transitionTo ( location : RawLocation , cb ? : Function ) {
35
+ transitionTo ( location : RawLocation , onComplete ? : Function , onAbort ? : Function ) {
36
36
const route = this . router . match ( location , this . current )
37
37
this . confirmTransition ( route , ( ) => {
38
38
this . updateRoute ( route )
39
- cb && cb ( route )
39
+ onComplete && onComplete ( route )
40
40
this . ensureURL ( )
41
- } )
41
+ } , onAbort )
42
42
}
43
43
44
- confirmTransition ( route : Route , cb : Function ) {
44
+ confirmTransition ( route : Route , onComplete : Function , onAbort ? : Function ) {
45
45
const current = this . current
46
+ const abort = ( ) => { onAbort && onAbort ( ) }
46
47
if ( isSameRoute ( route , current ) ) {
47
48
this . ensureURL ( )
48
- return
49
+ return abort ( )
49
50
}
50
51
51
52
const {
@@ -66,14 +67,18 @@ export class History {
66
67
67
68
this . pending = route
68
69
const iterator = ( hook : NavigationGuard , next ) => {
69
- if ( this . pending !== route ) return
70
+ if ( this . pending !== route ) {
71
+ return abort ( )
72
+ }
70
73
hook ( route , current , ( to : any ) => {
71
74
if ( to === false ) {
72
75
// next(false) -> abort navigation, ensure current URL
73
76
this . ensureURL ( true )
77
+ abort ( )
74
78
} else if ( typeof to === 'string' || typeof to === 'object' ) {
75
79
// next('/') or next({ path: '/' }) -> redirect
76
80
( typeof to === 'object' && to . replace ) ? this . replace ( to ) : this . push ( to )
81
+ abort ( )
77
82
} else {
78
83
// confirm transition and pass on the value
79
84
next ( to )
@@ -89,14 +94,15 @@ export class History {
89
94
// wait until async components are resolved before
90
95
// extracting in-component enter guards
91
96
runQueue ( enterGuards , iterator , ( ) => {
92
- if ( this . pending === route ) {
93
- this . pending = null
94
- cb ( route )
95
- if ( this . router . app ) {
96
- this . router . app . $nextTick ( ( ) => {
97
- postEnterCbs . forEach ( cb => cb ( ) )
98
- } )
99
- }
97
+ if ( this . pending !== route ) {
98
+ return abort ( )
99
+ }
100
+ this . pending = null
101
+ onComplete ( route )
102
+ if ( this . router . app ) {
103
+ this . router . app . $nextTick ( ( ) => {
104
+ postEnterCbs . forEach ( cb => cb ( ) )
105
+ } )
100
106
}
101
107
} )
102
108
} )
0 commit comments