File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -13,30 +13,35 @@ export default class VueRouter {
1313
1414 app : any ;
1515 options : RouterOptions ;
16- mode : 'hash' | 'history' | 'abstract' ;
16+ mode : string ;
1717 history : HashHistory | HTML5History | AbstractHistory ;
1818 match : Matcher ;
19+ fallback : boolean ;
1920
2021 constructor ( options : RouterOptions = { } ) {
21- assert (
22- install . installed ,
23- `not installed. Make sure to call \`Vue.use(VueRouter)\` ` +
24- `before mounting root instance.`
25- )
26-
2722 this . app = null
2823 this . options = options
2924 this . match = createMatcher ( options . routes || [ ] )
3025
3126 let mode = options . mode || 'hash'
32- const fallback = mode === 'history' && ! supportsHistory
33- if ( fallback ) {
27+ this . fallback = mode === 'history' && ! supportsHistory
28+ if ( this . fallback ) {
3429 mode = 'hash'
3530 }
3631 if ( ! inBrowser ) {
3732 mode = 'abstract'
3833 }
34+ this . mode = mode
35+ }
3936
37+ init ( app : any /* Vue component instance */ ) {
38+ assert (
39+ install . installed ,
40+ `not installed. Make sure to call \`Vue.use(VueRouter)\` ` +
41+ `before creating root instance.`
42+ )
43+
44+ const { mode, options, fallback } = this
4045 switch ( mode ) {
4146 case 'history' :
4247 this . history = new HTML5History ( this , options . base )
@@ -51,8 +56,7 @@ export default class VueRouter {
5156 assert ( false , `invalid mode: ${ mode } ` )
5257 }
5358
54- this . mode = mode
55-
59+ this . app = app
5660 this . history . listen ( route => {
5761 this . app . _route = route
5862 } )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export function install (Vue) {
1717 beforeCreate ( ) {
1818 if ( this . $options . router ) {
1919 this . _router = this . $options . router
20- this . _router . app = this
20+ this . _router . init ( this )
2121 Vue . util . defineReactive ( this , '_route' , this . _router . history . current )
2222 }
2323 }
You can’t perform that action at this time.
0 commit comments