@@ -112,13 +112,15 @@ export class History {
112
112
activated
113
113
} = resolveQueue ( this . current . matched , route . matched )
114
114
115
+ const postCbs = [ ]
116
+ const isValid = ( ) => this . current === route
115
117
const queue : Array < ?NavigationGuard > = [ ] . concat (
116
118
// in-component leave guards
117
119
extractLeaveGuards ( deactivated ) ,
118
120
// global before hooks
119
121
this . router . beforeHooks ,
120
122
// in-component update hooks
121
- extractUpdateHooks ( updated ) ,
123
+ extractUpdateHooks ( updated , postCbs , isValid ) ,
122
124
// in-config enter guards
123
125
activated . map ( m => m . beforeEnter ) ,
124
126
// async components
@@ -161,11 +163,9 @@ export class History {
161
163
}
162
164
163
165
runQueue ( queue , iterator , ( ) => {
164
- const postEnterCbs = [ ]
165
- const isValid = ( ) => this . current === route
166
166
// wait until async components are resolved before
167
167
// extracting in-component enter guards
168
- const enterGuards = extractEnterGuards ( activated , postEnterCbs , isValid )
168
+ const enterGuards = extractEnterGuards ( activated , postCbs , isValid )
169
169
const queue = enterGuards . concat ( this . router . resolveHooks )
170
170
runQueue ( queue , iterator , ( ) => {
171
171
if ( this . pending !== route ) {
@@ -175,7 +175,7 @@ export class History {
175
175
onComplete ( route )
176
176
if ( this . router . app ) {
177
177
this . router . app . $nextTick ( ( ) => {
178
- postEnterCbs . forEach ( cb => { cb ( ) } )
178
+ postCbs . forEach ( cb => { cb ( ) } )
179
179
} )
180
180
}
181
181
} )
@@ -266,10 +266,6 @@ function extractLeaveGuards (deactivated: Array<RouteRecord>): Array<?Function>
266
266
return extractGuards ( deactivated , 'beforeRouteLeave' , bindGuard , true )
267
267
}
268
268
269
- function extractUpdateHooks ( updated : Array < RouteRecord > ) : Array < ?Function > {
270
- return extractGuards ( updated , 'beforeRouteUpdate' , bindGuard )
271
- }
272
-
273
269
function bindGuard ( guard : NavigationGuard , instance : ?_Vue ) : ?NavigationGuard {
274
270
if ( instance ) {
275
271
return function boundRouteGuard ( ) {
@@ -278,24 +274,37 @@ function bindGuard (guard: NavigationGuard, instance: ?_Vue): ?NavigationGuard {
278
274
}
279
275
}
280
276
277
+ function extractUpdateHooks (
278
+ updated : Array < RouteRecord > ,
279
+ cbs : Array < Function > ,
280
+ isValid : ( ) = > boolean
281
+ ) : Array < ?Function > {
282
+ return extractGuards ( updated , 'beforeRouteUpdate' , ( guard , instance , match , key ) => {
283
+ var boundGuard = bindGuard ( guard , instance )
284
+ if ( boundGuard ) {
285
+ return bindCbGuard ( boundGuard , match , key , cbs , isValid )
286
+ }
287
+ } )
288
+ }
289
+
281
290
function extractEnterGuards (
282
291
activated : Array < RouteRecord > ,
283
292
cbs : Array < Function > ,
284
293
isValid : ( ) = > boolean
285
294
) : Array < ?Function > {
286
295
return extractGuards ( activated , 'beforeRouteEnter' , ( guard , _ , match , key ) => {
287
- return bindEnterGuard ( guard , match , key , cbs , isValid )
296
+ return bindCbGuard ( guard , match , key , cbs , isValid )
288
297
} )
289
298
}
290
299
291
- function bindEnterGuard (
300
+ function bindCbGuard (
292
301
guard : NavigationGuard ,
293
302
match : RouteRecord ,
294
303
key : string ,
295
304
cbs : Array < Function > ,
296
305
isValid : ( ) = > boolean
297
306
) : NavigationGuard {
298
- return function routeEnterGuard ( to , from , next ) {
307
+ return function ( to , from , next ) {
299
308
return guard ( to , from , cb => {
300
309
next ( cb )
301
310
if ( typeof cb === 'function' ) {
0 commit comments