@@ -32,20 +32,21 @@ export class History {
3232 this . cb = cb
3333 }
3434
35- transitionTo ( location : RawLocation , cb ? : Function ) {
35+ transitionTo ( location : RawLocation , onComplete ? : Function , onAbort ? : Function ) {
3636 const route = this . router . match ( location , this . current )
3737 this . confirmTransition ( route , ( ) => {
3838 this . updateRoute ( route )
39- cb && cb ( route )
39+ onComplete && onComplete ( route )
4040 this . ensureURL ( )
41- } )
41+ } , onAbort )
4242 }
4343
44- confirmTransition ( route : Route , cb : Function ) {
44+ confirmTransition ( route : Route , onComplete : Function , onAbort ? : Function ) {
4545 const current = this . current
46+ const abort = ( ) => { onAbort && onAbort ( ) }
4647 if ( isSameRoute ( route , current ) ) {
4748 this . ensureURL ( )
48- return
49+ return abort ( )
4950 }
5051
5152 const {
@@ -66,14 +67,18 @@ export class History {
6667
6768 this . pending = route
6869 const iterator = ( hook : NavigationGuard , next ) => {
69- if ( this . pending !== route ) return
70+ if ( this . pending !== route ) {
71+ return abort ( )
72+ }
7073 hook ( route , current , ( to : any ) => {
7174 if ( to === false ) {
7275 // next(false) -> abort navigation, ensure current URL
7376 this . ensureURL ( true )
77+ abort ( )
7478 } else if ( typeof to === 'string' || typeof to === 'object' ) {
7579 // next('/') or next({ path: '/' }) -> redirect
7680 ( typeof to === 'object' && to . replace ) ? this . replace ( to ) : this . push ( to )
81+ abort ( )
7782 } else {
7883 // confirm transition and pass on the value
7984 next ( to )
@@ -89,14 +94,15 @@ export class History {
8994 // wait until async components are resolved before
9095 // extracting in-component enter guards
9196 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+ } )
100106 }
101107 } )
102108 } )
0 commit comments