@@ -2,28 +2,45 @@ export default function (Vue) {
2
2
3
3
const _ = Vue . util
4
4
const mixin = {
5
- created : function ( ) {
6
- var route = this . $root . $route
5
+ init : function ( ) {
6
+ const route = this . $root . $route
7
7
if ( route ) {
8
8
route . router . _children . push ( this )
9
9
if ( ! this . $route ) {
10
- if ( this . _defineMeta ) {
11
- // 0.12 compat
12
- this . _defineMeta ( '$route' , route )
13
- } else {
14
- _ . defineReactive ( this , '$route' , route )
15
- }
10
+ _ . defineReactive ( this , '$route' , route )
16
11
}
17
12
}
18
13
} ,
19
14
beforeDestroy : function ( ) {
20
- var route = this . $root . $route
15
+ const route = this . $root . $route
21
16
if ( route ) {
22
17
route . router . _children . $remove ( this )
23
18
}
24
19
}
25
20
}
26
21
22
+ // pre 1.0.0-rc compat
23
+ if ( ! Vue . config . optionMergeStrategies ||
24
+ ! Vue . config . optionMergeStrategies . init ) {
25
+ delete mixin . init
26
+ const init = Vue . prototype . _init
27
+ Vue . prototype . _init = function ( options ) {
28
+ const root = options . _parent || options . parent || this
29
+ const route = root . $route
30
+ if ( route ) {
31
+ route . router . _children . push ( this )
32
+ if ( ! this . $route ) {
33
+ if ( this . _defineMeta ) {
34
+ this . _defineMeta ( '$route' , route )
35
+ } else {
36
+ _ . defineReactive ( this , '$route' , route )
37
+ }
38
+ }
39
+ }
40
+ init . call ( this , options )
41
+ }
42
+ }
43
+
27
44
if ( Vue . mixin ) {
28
45
Vue . mixin ( mixin )
29
46
} else {
0 commit comments