@@ -90,7 +90,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
90
90
function checkCanceledNavigation (
91
91
to : RouteLocationNormalized ,
92
92
from : RouteLocationNormalized
93
- ) : NavigationFailure | void {
93
+ ) : NavigationFailure | undefined {
94
94
if ( pendingLocation !== to ) {
95
95
return createRouterError < NavigationFailure > (
96
96
ErrorTypes . NAVIGATION_CANCELLED ,
@@ -100,14 +100,16 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
100
100
}
101
101
)
102
102
}
103
+
104
+ return undefined
103
105
}
104
106
105
107
function checkCanceledNavigationAndReject (
106
108
to : RouteLocationNormalized ,
107
109
from : RouteLocationNormalized
108
- ) : Promise < void > {
110
+ ) {
109
111
const error = checkCanceledNavigation ( to , from )
110
- return error ? Promise . reject ( error ) : Promise . resolve ( )
112
+ if ( error ) throw error
111
113
}
112
114
113
115
function runWithContext < T > ( fn : ( ) => T ) : T {
@@ -118,11 +120,10 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
118
120
: fn ( )
119
121
}
120
122
121
- function runGuardQueue ( guards : Lazy < any > [ ] ) : Promise < any > {
122
- return guards . reduce (
123
- ( promise , guard ) => promise . then ( ( ) => runWithContext ( guard ) ) ,
124
- Promise . resolve ( )
125
- )
123
+ async function runGuardQueue ( guards : Lazy < any > [ ] ) : Promise < any > {
124
+ for ( const guard of guards ) {
125
+ await runWithContext ( guard )
126
+ }
126
127
}
127
128
128
129
let ready : boolean = false
@@ -146,14 +147,11 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
146
147
navigationInfo
147
148
)
148
149
149
- const canceledNavigationCheck = checkCanceledNavigationAndReject . bind (
150
- null ,
151
- to ,
152
- from
153
- )
150
+ const canceledNavigationCheck = async ( ) => {
151
+ checkCanceledNavigationAndReject ( to , from )
152
+ }
154
153
155
154
guards . push ( canceledNavigationCheck )
156
-
157
155
await runGuardQueue ( guards )
158
156
159
157
// check global guards beforeEach
0 commit comments