Skip to content

Commit 8639a74

Browse files
committed
update vue-router annotations
1 parent 6e5dc49 commit 8639a74

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

vue-router-src/components/view.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
let depth = 0
3636
/* 标记是否是待用(非alive状态)) */
3737
let inactive = false
38-
/* _routerRoot中中存放了跟组件的势力,这边循环向上级访问,直到访问到根组件,得到depth深度 */
38+
/* _routerRoot中中存放了根组件的势力,这边循环向上级访问,直到访问到根组件,得到depth深度 */
3939
while (parent && parent._routerRoot !== parent) {
4040
if (parent.$vnode && parent.$vnode.data.routerView) {
4141
depth++
@@ -57,22 +57,28 @@ export default {
5757

5858
const matched = route.matched[depth]
5959
// render empty node if no matched route
60+
/* 如果没有匹配到的路由,则渲染一个空节点 */
6061
if (!matched) {
6162
cache[name] = null
6263
return h()
6364
}
6465

66+
/* 从成功匹配到的路由中取出组件 */
6567
const component = cache[name] = matched.components[name]
6668

6769
// attach instance registration hook
6870
// this will be called in the instance's injected lifecycle hooks
69-
data.registerRouteInstance = (vm, val) => {
71+
/* 注册实例的registration钩子,这个函数将在实例被注入的加入到组件的生命钩子(beforeCreate与destroyed)中被调用 */
72+
data.registerRouteInstance = (vm, val) => {
73+
/* 第二个值不存在的时候为注销 */
7074
// val could be undefined for unregistration
75+
/* 获取组件实例 */
7176
const current = matched.instances[name]
7277
if (
7378
(val && current !== vm) ||
7479
(!val && current === vm)
7580
) {
81+
/* 这里有两种情况,一种是val存在,则用val替换当前组件实例,另一种则是val不存在,则直接将val(这个时候其实是一个undefined)赋给instances */
7682
matched.instances[name] = val
7783
}
7884
}

0 commit comments

Comments
 (0)