@@ -51,15 +51,18 @@ export class History {
51
51
activated
52
52
} = resolveQueue ( this . current . matched , route . matched )
53
53
54
+ const postEnterCbs = [ ]
54
55
const queue = [ ] . concat (
55
- // deactivate guards
56
+ // in-component leave guards
56
57
extractLeaveGuards ( deactivated ) ,
57
58
// global before hooks
58
59
this . router . beforeHooks ,
59
- // activate guards
60
+ // enter guards
60
61
activated . map ( m => m . beforeEnter ) ,
61
62
// async components
62
- resolveAsyncComponents ( activated )
63
+ resolveAsyncComponents ( activated ) ,
64
+ // in-component enter guards
65
+ extractEnterGuards ( activated , postEnterCbs )
63
66
) . filter ( _ => _ )
64
67
65
68
this . pending = route
@@ -72,6 +75,9 @@ export class History {
72
75
if ( isSameRoute ( route , this . pending ) ) {
73
76
this . pending = null
74
77
cb ( route )
78
+ this . router . app . $nextTick ( ( ) => {
79
+ postEnterCbs . forEach ( cb => cb ( ) )
80
+ } )
75
81
}
76
82
}
77
83
)
@@ -128,13 +134,29 @@ function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> {
128
134
return flatMapComponents ( matched , ( def , instance ) => {
129
135
const guard = def && def . beforeRouteLeave
130
136
if ( guard ) {
131
- return function routeGuard ( ) {
137
+ return function routeLeaveGuard ( ) {
132
138
return guard . apply ( instance , arguments )
133
139
}
134
140
}
135
141
} ) . reverse ( )
136
142
}
137
143
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
+
138
160
function resolveAsyncComponents ( matched : Array < RouteRecord > ) : Array < ?Function > {
139
161
return flatMapComponents ( matched , ( def , _ , match , key ) => {
140
162
// if it's a function and doesn't have Vue options attached,
0 commit comments