Skip to content

Commit 170c449

Browse files
fix: fixed enter cb not called in out-in transitions still
1 parent dd0efda commit 170c449

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

Diff for: src/components/view.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,12 @@ export default {
8181
vnode.componentInstance !== matched.instances[name]
8282
) {
8383
matched.instances[name] = vnode.componentInstance
84-
// if the route transition has already been confirmed then we weren't
85-
// able to call the cbs during confirmation as the component was not
86-
// registered yet, so we call it here.
87-
if (matched.enteredCbs[name]) {
88-
handleRouteEntered(matched, name)
89-
}
9084
}
85+
86+
// if the route transition has already been confirmed then we weren't
87+
// able to call the cbs during confirmation as the component was not
88+
// registered yet, so we call it here.
89+
handleRouteEntered(route)
9190
}
9291

9392
// resolve props

Diff for: src/history/base.js

+5-17
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ export class History {
177177
}
178178

179179
runQueue(queue, iterator, () => {
180-
const enteredCbs = []
181180
// wait until async components are resolved before
182181
// extracting in-component enter guards
183-
const enterGuards = extractEnterGuards(activated, enteredCbs)
182+
const enterGuards = extractEnterGuards(activated)
184183
const queue = enterGuards.concat(this.router.resolveHooks)
185184
runQueue(queue, iterator, () => {
186185
if (this.pending !== route) {
@@ -190,9 +189,7 @@ export class History {
190189
onComplete(route)
191190
if (this.router.app) {
192191
this.router.app.$nextTick(() => {
193-
enteredCbs.forEach(cb => {
194-
cb()
195-
})
192+
handleRouteEntered(route)
196193
})
197194
}
198195
})
@@ -296,23 +293,21 @@ function bindGuard (guard: NavigationGuard, instance: ?_Vue): ?NavigationGuard {
296293
}
297294

298295
function extractEnterGuards (
299-
activated: Array<RouteRecord>,
300-
cbs: Array<Function>,
296+
activated: Array<RouteRecord>
301297
): Array<?Function> {
302298
return extractGuards(
303299
activated,
304300
'beforeRouteEnter',
305301
(guard, _, match, key) => {
306-
return bindEnterGuard(guard, match, key, cbs)
302+
return bindEnterGuard(guard, match, key)
307303
}
308304
)
309305
}
310306

311307
function bindEnterGuard (
312308
guard: NavigationGuard,
313309
match: RouteRecord,
314-
key: string,
315-
cbs: Array<Function>,
310+
key: string
316311
): NavigationGuard {
317312
return function routeEnterGuard (to, from, next) {
318313
return guard(to, from, cb => {
@@ -321,13 +316,6 @@ function bindEnterGuard (
321316
match.enteredCbs[key] = []
322317
}
323318
match.enteredCbs[key].push(cb)
324-
cbs.push(() => {
325-
// if the instance is registered call the cb here, otherwise it will
326-
// get called when it is registered in the component's lifecycle hooks
327-
if (match.instances[key]) {
328-
handleRouteEntered(match, key)
329-
}
330-
})
331319
}
332320
next(cb)
333321
})

Diff for: src/util/route.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,17 @@ function queryIncludes (current: Dictionary<string>, target: Dictionary<string>)
131131
return true
132132
}
133133

134-
export function handleRouteEntered (record: RouteRecord, name: string) {
135-
const instance = record.instances[name]
136-
const cbs = record.enteredCbs[name]
137-
if (!instance || !cbs) return
138-
delete record.enteredCbs[name]
139-
for (let i = 0; i < cbs.length; i++) {
140-
cbs[i](instance)
134+
export function handleRouteEntered (route: Route) {
135+
for (let i = 0; i < route.matched.length; i++) {
136+
const record = route.matched[i]
137+
for (const name in record.instances) {
138+
const instance = record.instances[name]
139+
const cbs = record.enteredCbs[name]
140+
if (!instance || !cbs) continue
141+
delete record.enteredCbs[name]
142+
for (let i = 0; i < cbs.length; i++) {
143+
cbs[i](instance)
144+
}
145+
}
141146
}
142147
}

0 commit comments

Comments
 (0)