@@ -136,6 +136,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
136
136
const [ leavingRecords , updatingRecords , enteringRecords ] =
137
137
extractChangingRecords ( to , from )
138
138
139
+ // run the queue of per route beforeRouteLeave guards
139
140
let guards = extractComponentsGuards (
140
141
leavingRecords . reverse ( ) ,
141
142
'beforeRouteLeave' ,
@@ -155,20 +156,25 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
155
156
156
157
await runGuardQueue ( guards )
157
158
159
+ // check global guards beforeEach
158
160
guards = [ ]
159
161
for ( const guard of beforeGuards . list ( ) ) {
160
162
guards . push ( guardToPromiseFn ( guard , to , from , { info : navigationInfo } ) )
161
163
}
164
+ guards . push ( canceledNavigationCheck )
162
165
await runGuardQueue ( guards )
163
166
167
+ // check in components beforeRouteUpdate
164
168
guards = extractComponentsGuards (
165
169
updatingRecords ,
166
170
'beforeRouteUpdate' ,
167
171
to ,
168
172
from
169
173
)
174
+ guards . push ( canceledNavigationCheck )
170
175
await runGuardQueue ( guards )
171
176
177
+ // check the route beforeEnter
172
178
guards = [ ]
173
179
for ( const record of enteringRecords ) {
174
180
if ( record . beforeEnter ) {
@@ -186,23 +192,31 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
186
192
}
187
193
}
188
194
}
195
+ guards . push ( canceledNavigationCheck )
189
196
await runGuardQueue ( guards )
190
197
198
+ // NOTE: at this point to.matched is normalized and does not contain any () => Promise<Component>
199
+ // clear existing enterCallbacks, these are added by extractComponentsGuards
200
+ to . matched . forEach ( record => ( record . enterCallbacks = { } ) )
201
+
191
202
// Resolve async components and run beforeRouteEnter
192
203
guards = extractComponentsGuards (
193
204
enteringRecords ,
194
205
'beforeRouteEnter' ,
195
206
to ,
196
207
from ,
197
- undefined ,
208
+ runWithContext ,
198
209
navigationInfo
199
210
)
211
+ guards . push ( canceledNavigationCheck )
200
212
await runGuardQueue ( guards )
201
213
214
+ // check global guards beforeResolve
202
215
guards = [ ]
203
216
for ( const guard of beforeResolveGuards . list ( ) ) {
204
217
guards . push ( guardToPromiseFn ( guard , to , from , { info : navigationInfo } ) )
205
218
}
219
+ guards . push ( canceledNavigationCheck )
206
220
await runGuardQueue ( guards )
207
221
}
208
222
0 commit comments