Skip to content

Commit aff081e

Browse files
refactor: a little bit more refactoring
1 parent 429a38c commit aff081e

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/components/view.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ export default {
7171
// in case the same component instance is reused across different routes
7272
;(data.hook || (data.hook = {})).prepatch = (_, vnode) => {
7373
matched.instances[name] = vnode.componentInstance
74-
// if the route transition has already been confirmed then we weren't
75-
// able to call the cb during confirmation as the component was not
76-
// registered yet, so we call it here.
77-
matched.enteredCbs
78-
handleRouteEntered(matched, name)
7974
}
8075

8176
// register instance in init hook
@@ -86,7 +81,12 @@ export default {
8681
vnode.componentInstance !== matched.instances[name]
8782
) {
8883
matched.instances[name] = vnode.componentInstance
89-
handleRouteEntered(matched, name)
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+
}
9090
}
9191
}
9292

src/history/base.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ function bindEnterGuard (
324324
cbs.push(() => {
325325
// if the instance is registered call the cb here, otherwise it will
326326
// get called when it is registered in the component's lifecycle hooks
327-
handleRouteEntered(match, key)
327+
if (match.instances[key]) {
328+
handleRouteEntered(match, key)
329+
}
328330
})
329331
}
330332
next(cb)

src/util/route.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ function queryIncludes (current: Dictionary<string>, target: Dictionary<string>)
132132
}
133133

134134
export function handleRouteEntered (record: RouteRecord, name: string) {
135-
if (record.instances[name] && record.enteredCbs[name]) {
136-
const instance = record.instances[name]
137-
const cbs = record.enteredCbs[name]
138-
delete record.enteredCbs[name]
139-
for (let i = 0; i < cbs.length; i++) {
140-
cbs[i](instance)
141-
}
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)
142141
}
143142
}

0 commit comments

Comments
 (0)