@@ -178,10 +178,9 @@ export class History {
178
178
179
179
runQueue ( queue , iterator , ( ) => {
180
180
const postEnterCbs = [ ]
181
- const isValid = ( ) => this . current === route
182
181
// wait until async components are resolved before
183
182
// extracting in-component enter guards
184
- const enterGuards = extractEnterGuards ( activated , postEnterCbs , isValid )
183
+ const enterGuards = extractEnterGuards ( activated , postEnterCbs )
185
184
const queue = enterGuards . concat ( this . router . resolveHooks )
186
185
runQueue ( queue , iterator , ( ) => {
187
186
if ( this . pending !== route ) {
@@ -299,13 +298,12 @@ function bindGuard (guard: NavigationGuard, instance: ?_Vue): ?NavigationGuard {
299
298
function extractEnterGuards (
300
299
activated : Array < RouteRecord > ,
301
300
cbs : Array < Function > ,
302
- isValid : ( ) = > boolean
303
301
) : Array < ?Function > {
304
302
return extractGuards (
305
303
activated ,
306
304
'beforeRouteEnter' ,
307
305
( guard , _ , match , key ) = > {
308
- return bindEnterGuard ( guard , match , key , cbs , isValid )
306
+ return bindEnterGuard ( guard , match , key , cbs )
309
307
}
310
308
)
311
309
}
@@ -315,39 +313,27 @@ function bindEnterGuard (
315
313
match : RouteRecord ,
316
314
key : string ,
317
315
cbs : Array < Function > ,
318
- isValid : ( ) = > boolean
319
316
) : NavigationGuard {
320
317
return function routeEnterGuard ( to , from , next ) {
321
318
return guard ( to , from , cb => {
322
319
if ( typeof cb === 'function' ) {
320
+ match . pendingCbs [ key ] = cb
323
321
cbs . push ( ( ) => {
324
- // #750
325
- // if a router-view is wrapped with an out-in transition,
326
- // the instance may not have been registered at this time.
327
- // we will need to poll for registration until current route
328
- // is no longer valid.
329
- poll ( cb , match . instances , key , isValid )
322
+ // if the instance is registered call the cb here, otherwise it will
323
+ // get called when it is registered in the component's lifecycle hooks
324
+ tryFinalizeTransition ( match , key )
330
325
} )
331
326
}
332
327
next ( cb )
333
328
} )
334
329
}
335
330
}
336
331
337
- function poll (
338
- cb : any , // somehow flow cannot infer this is a function
339
- instances : Object ,
340
- key : string ,
341
- isValid : ( ) = > boolean
342
- ) {
343
- if (
344
- instances [ key ] &&
345
- ! instances [ key ] . _isBeingDestroyed // do not reuse being destroyed instance
346
- ) {
347
- cb ( instances [ key ] )
348
- } else if ( isValid ( ) ) {
349
- setTimeout ( ( ) => {
350
- poll ( cb , instances , key , isValid )
351
- } , 16 )
332
+ export function tryFinalizeTransition ( record : RouteRecord , name : string ) {
333
+ if ( record . instances [ name ] && record . pendingCbs [ name ] ) {
334
+ const instance = record . instances [ name ]
335
+ const cb = record . pendingCbs [ name ]
336
+ delete record . pendingCbs [ name ]
337
+ cb ( instance )
352
338
}
353
339
}
0 commit comments