@@ -9,14 +9,6 @@ export function install (Vue) {
99
1010 _Vue = Vue
1111
12- Object . defineProperty ( Vue . prototype , '$router' , {
13- get ( ) { return this . $root . _router }
14- } )
15-
16- Object . defineProperty ( Vue . prototype , '$route' , {
17- get ( ) { return this . $root . _route }
18- } )
19-
2012 const isDef = v => v !== undefined
2113
2214 const registerInstance = ( vm , callVal ) => {
@@ -29,9 +21,12 @@ export function install (Vue) {
2921 Vue . mixin ( {
3022 beforeCreate ( ) {
3123 if ( isDef ( this . $options . router ) ) {
24+ this . _routerRoot = this
3225 this . _router = this . $options . router
3326 this . _router . init ( this )
3427 Vue . util . defineReactive ( this , '_route' , this . _router . history . current )
28+ } else {
29+ this . _routerRoot = ( this . $parent && this . $parent . _routerRoot ) || this
3530 }
3631 registerInstance ( this , this )
3732 } ,
@@ -40,6 +35,14 @@ export function install (Vue) {
4035 }
4136 } )
4237
38+ Object . defineProperty ( Vue . prototype , '$router' , {
39+ get ( ) { return this . _routerRoot . _router }
40+ } )
41+
42+ Object . defineProperty ( Vue . prototype , '$route' , {
43+ get ( ) { return this . _routerRoot . _route }
44+ } )
45+
4346 Vue . component ( 'router-view' , View )
4447 Vue . component ( 'router-link' , Link )
4548
0 commit comments