1
1
export default function ( Vue ) {
2
2
3
- const _ = Vue . util
3
+ const {
4
+ extend,
5
+ isArray,
6
+ defineReactive
7
+ } = Vue . util
4
8
5
9
// override Vue's init and destroy process to keep track of router instances
6
10
const init = Vue . prototype . _init
7
11
Vue . prototype . _init = function ( options ) {
8
12
options = options || { }
9
13
const root = options . _parent || options . parent || this
14
+ const router = root . $router
10
15
const route = root . $route
11
- if ( route ) {
12
- route . router . _children . push ( this )
13
- if ( ! this . $route ) {
14
- /* istanbul ignore if */
15
- if ( this . _defineMeta ) {
16
- // 0.12
17
- this . _defineMeta ( '$route' , route )
18
- } else {
19
- // 1.0
20
- _ . defineReactive ( this , '$route' , route )
21
- }
16
+ if ( router ) {
17
+ // expose router
18
+ this . $router = router
19
+ router . _children . push ( this )
20
+ /* istanbul ignore if */
21
+ if ( this . _defineMeta ) {
22
+ // 0.12
23
+ this . _defineMeta ( '$route' , route )
24
+ } else {
25
+ // 1.0
26
+ defineReactive ( this , '$route' , route )
22
27
}
23
28
}
24
29
init . call ( this , options )
@@ -27,9 +32,8 @@ export default function (Vue) {
27
32
const destroy = Vue . prototype . _destroy
28
33
Vue . prototype . _destroy = function ( ) {
29
34
if ( ! this . _isBeingDestroyed ) {
30
- const route = this . $root . $route
31
- if ( route ) {
32
- route . router . _children . $remove ( this )
35
+ if ( this . $router ) {
36
+ this . $router . _children . $remove ( this )
33
37
}
34
38
destroy . apply ( this , arguments )
35
39
}
@@ -44,14 +48,14 @@ export default function (Vue) {
44
48
if ( ! childVal ) return parentVal
45
49
if ( ! parentVal ) return childVal
46
50
const ret = { }
47
- _ . extend ( ret , parentVal )
51
+ extend ( ret , parentVal )
48
52
for ( let key in childVal ) {
49
53
let a = ret [ key ]
50
54
let b = childVal [ key ]
51
55
// for data, activate and deactivate, we need to merge them into
52
56
// arrays similar to lifecycle hooks.
53
57
if ( a && hooksToMergeRE . test ( key ) ) {
54
- ret [ key ] = ( _ . isArray ( a ) ? a : [ a ] ) . concat ( b )
58
+ ret [ key ] = ( isArray ( a ) ? a : [ a ] ) . concat ( b )
55
59
} else {
56
60
ret [ key ] = b
57
61
}
0 commit comments