File tree 1 file changed +8
-2
lines changed
vue-router-src/components
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export default {
35
35
let depth = 0
36
36
/* 标记是否是待用(非alive状态)) */
37
37
let inactive = false
38
- /* _routerRoot中中存放了跟组件的势力 ,这边循环向上级访问,直到访问到根组件,得到depth深度 */
38
+ /* _routerRoot中中存放了根组件的势力 ,这边循环向上级访问,直到访问到根组件,得到depth深度 */
39
39
while ( parent && parent . _routerRoot !== parent ) {
40
40
if ( parent . $vnode && parent . $vnode . data . routerView ) {
41
41
depth ++
@@ -57,22 +57,28 @@ export default {
57
57
58
58
const matched = route . matched [ depth ]
59
59
// render empty node if no matched route
60
+ /* 如果没有匹配到的路由,则渲染一个空节点 */
60
61
if ( ! matched ) {
61
62
cache [ name ] = null
62
63
return h ( )
63
64
}
64
65
66
+ /* 从成功匹配到的路由中取出组件 */
65
67
const component = cache [ name ] = matched . components [ name ]
66
68
67
69
// attach instance registration hook
68
70
// 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
+ /* 第二个值不存在的时候为注销 */
70
74
// val could be undefined for unregistration
75
+ /* 获取组件实例 */
71
76
const current = matched . instances [ name ]
72
77
if (
73
78
( val && current !== vm ) ||
74
79
( ! val && current === vm )
75
80
) {
81
+ /* 这里有两种情况,一种是val存在,则用val替换当前组件实例,另一种则是val不存在,则直接将val(这个时候其实是一个undefined)赋给instances */
76
82
matched . instances [ name ] = val
77
83
}
78
84
}
You can’t perform that action at this time.
0 commit comments