Skip to content

Commit 813cb25

Browse files
committed
add polling for out-in transitions (fix #750)
1 parent df39bd6 commit 813cb25

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Diff for: src/history/base.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ export class History {
8282

8383
runQueue(queue, iterator, () => {
8484
const postEnterCbs = []
85+
const enterGuards = extractEnterGuards(activated, postEnterCbs, () => {
86+
return this.current === route
87+
})
8588
// wait until async components are resolved before
8689
// extracting in-component enter guards
87-
runQueue(extractEnterGuards(activated, postEnterCbs), iterator, () => {
90+
runQueue(enterGuards, iterator, () => {
8891
if (this.pending === route) {
8992
this.pending = null
9093
cb(route)
@@ -155,7 +158,11 @@ function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> {
155158
}).reverse()
156159
}
157160

158-
function extractEnterGuards (matched: Array<RouteRecord>, cbs: Array<Function>): Array<?Function> {
161+
function extractEnterGuards (
162+
matched: Array<RouteRecord>,
163+
cbs: Array<Function>,
164+
isValid: () => boolean
165+
): Array<?Function> {
159166
return flatMapComponents(matched, (def, _, match, key) => {
160167
const guard = def && def.beforeRouteEnter
161168
if (guard) {
@@ -164,7 +171,12 @@ function extractEnterGuards (matched: Array<RouteRecord>, cbs: Array<Function>):
164171
next(cb)
165172
if (typeof cb === 'function') {
166173
cbs.push(() => {
167-
cb(match.instances[key])
174+
// #750
175+
// if a router-view is wrapped with an out-in transition,
176+
// the instance may not have been registered at this time.
177+
// we will need to poll for registration until current route
178+
// is no longer valid.
179+
poll(cb, match.instances, key, isValid)
168180
})
169181
}
170182
})
@@ -173,6 +185,17 @@ function extractEnterGuards (matched: Array<RouteRecord>, cbs: Array<Function>):
173185
})
174186
}
175187

188+
function poll (cb, instances, key, isValid) {
189+
if (instances[key]) {
190+
cb(instances[key])
191+
} else if (isValid()) {
192+
setTimeout(() => {
193+
console.log('polling')
194+
poll(cb, instances, key, isValid)
195+
}, 16)
196+
}
197+
}
198+
176199
function resolveAsyncComponents (matched: Array<RouteRecord>): Array<?Function> {
177200
return flatMapComponents(matched, (def, _, match, key) => {
178201
// if it's a function and doesn't have Vue options attached,

0 commit comments

Comments
 (0)