@@ -51,15 +51,18 @@ export class History {
5151 activated
5252 } = resolveQueue ( this . current . matched , route . matched )
5353
54+ const postEnterCbs = [ ]
5455 const queue = [ ] . concat (
55- // deactivate guards
56+ // in-component leave guards
5657 extractLeaveGuards ( deactivated ) ,
5758 // global before hooks
5859 this . router . beforeHooks ,
59- // activate guards
60+ // enter guards
6061 activated . map ( m => m . beforeEnter ) ,
6162 // async components
62- resolveAsyncComponents ( activated )
63+ resolveAsyncComponents ( activated ) ,
64+ // in-component enter guards
65+ extractEnterGuards ( activated , postEnterCbs )
6366 ) . filter ( _ => _ )
6467
6568 this . pending = route
@@ -72,6 +75,9 @@ export class History {
7275 if ( isSameRoute ( route , this . pending ) ) {
7376 this . pending = null
7477 cb ( route )
78+ this . router . app . $nextTick ( ( ) => {
79+ postEnterCbs . forEach ( cb => cb ( ) )
80+ } )
7581 }
7682 }
7783 )
@@ -128,13 +134,29 @@ function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> {
128134 return flatMapComponents ( matched , ( def , instance ) => {
129135 const guard = def && def . beforeRouteLeave
130136 if ( guard ) {
131- return function routeGuard ( ) {
137+ return function routeLeaveGuard ( ) {
132138 return guard . apply ( instance , arguments )
133139 }
134140 }
135141 } ) . reverse ( )
136142}
137143
144+ function extractEnterGuards ( matched : Array < RouteRecord > , cbs : Array < Function > ) : Array < ?Function > {
145+ return flatMapComponents ( matched , ( def , _ , match , key ) => {
146+ const guard = def && def . beforeRouteEnter
147+ if ( guard ) {
148+ return function routeEnterGuard ( route , redirect , next ) {
149+ return guard ( route , redirect , cb => {
150+ next ( )
151+ cb && cbs . push ( ( ) => {
152+ cb ( match . instances [ key ] && match . instances [ key ] . child )
153+ } )
154+ } )
155+ }
156+ }
157+ } )
158+ }
159+
138160function resolveAsyncComponents ( matched : Array < RouteRecord > ) : Array < ?Function > {
139161 return flatMapComponents ( matched , ( def , _ , match , key ) => {
140162 // if it's a function and doesn't have Vue options attached,
0 commit comments