@@ -5,7 +5,7 @@ import type Router from '../index'
55import { inBrowser } from '../util/dom'
66import { runQueue } from '../util/async'
77import { warn } from '../util/warn'
8- import { START , isSameRoute } from '../util/route'
8+ import { START , isSameRoute , handleRouteEntered } from '../util/route'
99import {
1010 flatten ,
1111 flatMapComponents ,
@@ -218,11 +218,9 @@ export class History {
218218 }
219219
220220 runQueue ( queue , iterator , ( ) => {
221- const postEnterCbs = [ ]
222- const isValid = ( ) => this . current === route
223221 // wait until async components are resolved before
224222 // extracting in-component enter guards
225- const enterGuards = extractEnterGuards ( activated , postEnterCbs , isValid )
223+ const enterGuards = extractEnterGuards ( activated )
226224 const queue = enterGuards . concat ( this . router . resolveHooks )
227225 runQueue ( queue , iterator , ( ) => {
228226 if ( this . pending !== route ) {
@@ -232,9 +230,7 @@ export class History {
232230 onComplete ( route )
233231 if ( this . router . app ) {
234232 this . router . app . $nextTick ( ( ) => {
235- postEnterCbs . forEach ( cb => {
236- cb ( )
237- } )
233+ handleRouteEntered ( route )
238234 } )
239235 }
240236 } )
@@ -352,57 +348,31 @@ function bindGuard (guard: NavigationGuard, instance: ?_Vue): ?NavigationGuard {
352348}
353349
354350function extractEnterGuards (
355- activated : Array < RouteRecord > ,
356- cbs : Array < Function > ,
357- isValid : ( ) = > boolean
351+ activated : Array < RouteRecord >
358352) : Array < ?Function > {
359353 return extractGuards (
360354 activated ,
361355 'beforeRouteEnter' ,
362356 ( guard , _ , match , key ) = > {
363- return bindEnterGuard ( guard , match , key , cbs , isValid )
357+ return bindEnterGuard ( guard , match , key )
364358 }
365359 )
366360}
367361
368362function bindEnterGuard (
369363 guard : NavigationGuard ,
370364 match : RouteRecord ,
371- key : string ,
372- cbs : Array < Function > ,
373- isValid : ( ) = > boolean
365+ key : string
374366) : NavigationGuard {
375367 return function routeEnterGuard ( to , from , next ) {
376368 return guard ( to , from , cb => {
377369 if ( typeof cb === 'function' ) {
378- cbs . push ( ( ) => {
379- // #750
380- // if a router-view is wrapped with an out-in transition,
381- // the instance may not have been registered at this time.
382- // we will need to poll for registration until current route
383- // is no longer valid.
384- poll ( cb , match . instances , key , isValid )
385- } )
370+ if ( ! match . enteredCbs [ key ] ) {
371+ match . enteredCbs [ key ] = [ ]
372+ }
373+ match . enteredCbs [ key ] . push ( cb )
386374 }
387375 next ( cb )
388376 } )
389377 }
390378}
391-
392- function poll (
393- cb : any , // somehow flow cannot infer this is a function
394- instances : Object ,
395- key : string ,
396- isValid : ( ) = > boolean
397- ) {
398- if (
399- instances [ key ] &&
400- ! instances [ key ] . _isBeingDestroyed // do not reuse being destroyed instance
401- ) {
402- cb ( instances [ key ] )
403- } else if ( isValid ( ) ) {
404- setTimeout ( ( ) => {
405- poll ( cb , instances , key , isValid )
406- } , 16 )
407- }
408- }
0 commit comments