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 {
13
13
14
14
app : any ;
15
15
options : RouterOptions ;
16
- mode : 'hash' | 'history' | 'abstract' ;
16
+ mode : string ;
17
17
history : HashHistory | HTML5History | AbstractHistory ;
18
18
match : Matcher ;
19
+ fallback : boolean ;
19
20
20
21
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
-
27
22
this . app = null
28
23
this . options = options
29
24
this . match = createMatcher ( options . routes || [ ] )
30
25
31
26
let mode = options . mode || 'hash'
32
- const fallback = mode === 'history' && ! supportsHistory
33
- if ( fallback ) {
27
+ this . fallback = mode === 'history' && ! supportsHistory
28
+ if ( this . fallback ) {
34
29
mode = 'hash'
35
30
}
36
31
if ( ! inBrowser ) {
37
32
mode = 'abstract'
38
33
}
34
+ this . mode = mode
35
+ }
39
36
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
40
45
switch ( mode ) {
41
46
case 'history' :
42
47
this . history = new HTML5History ( this , options . base )
@@ -51,8 +56,7 @@ export default class VueRouter {
51
56
assert ( false , `invalid mode: ${ mode } ` )
52
57
}
53
58
54
- this . mode = mode
55
-
59
+ this . app = app
56
60
this . history . listen ( route => {
57
61
this . app . _route = route
58
62
} )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export function install (Vue) {
17
17
beforeCreate ( ) {
18
18
if ( this . $options . router ) {
19
19
this . _router = this . $options . router
20
- this . _router . app = this
20
+ this . _router . init ( this )
21
21
Vue . util . defineReactive ( this , '_route' , this . _router . history . current )
22
22
}
23
23
}
You can’t perform that action at this time.
0 commit comments