1
- import QueuingEvented from '../core/QueuingEvented ' ;
1
+ import Evented from '../core/Evented ' ;
2
2
import { RouteConfig , History , OutletContext , Params , RouterInterface , Route , RouterOptions } from './interfaces' ;
3
3
import { HashHistory } from './history/HashHistory' ;
4
4
import { EventObject } from '../core/Evented' ;
@@ -36,25 +36,22 @@ function matchingParams({ params: previousParams }: OutletContext, { params }: O
36
36
return Object . keys ( params ) . every ( ( key ) => previousParams [ key ] === params [ key ] ) ;
37
37
}
38
38
39
- export class Router extends QueuingEvented < { nav : NavEvent ; outlet : OutletEvent } > implements RouterInterface {
39
+ export class Router extends Evented < { nav : NavEvent ; outlet : OutletEvent } > implements RouterInterface {
40
40
private _routes : Route [ ] = [ ] ;
41
41
private _outletMap : { [ index : string ] : Route } = Object . create ( null ) ;
42
42
private _matchedOutlets : { [ index : string ] : OutletContext } = Object . create ( null ) ;
43
43
private _currentParams : Params = { } ;
44
44
private _currentQueryParams : Params = { } ;
45
45
private _defaultOutlet : string | undefined ;
46
- private _history : History ;
46
+ private _history ! : History ;
47
+ private _options : RouterOptions ;
47
48
48
49
constructor ( config : RouteConfig [ ] , options : RouterOptions = { } ) {
49
50
super ( ) ;
50
- const { HistoryManager = HashHistory , base , window } = options ;
51
+ this . _options = options ;
51
52
this . _register ( config ) ;
52
- this . _history = new HistoryManager ( { onChange : this . _onChange , base, window } ) ;
53
- if ( this . _matchedOutlets . errorOutlet && this . _defaultOutlet ) {
54
- const path = this . link ( this . _defaultOutlet ) ;
55
- if ( path ) {
56
- this . setPath ( path ) ;
57
- }
53
+ if ( options . autostart || true ) {
54
+ this . start ( ) ;
58
55
}
59
56
}
60
57
@@ -67,6 +64,17 @@ export class Router extends QueuingEvented<{ nav: NavEvent; outlet: OutletEvent
67
64
this . _history . set ( path ) ;
68
65
}
69
66
67
+ public start ( ) {
68
+ const { HistoryManager = HashHistory , base, window } = this . _options ;
69
+ this . _history = new HistoryManager ( { onChange : this . _onChange , base, window } ) ;
70
+ if ( this . _matchedOutlets . errorOutlet && this . _defaultOutlet ) {
71
+ const path = this . link ( this . _defaultOutlet ) ;
72
+ if ( path ) {
73
+ this . setPath ( path ) ;
74
+ }
75
+ }
76
+ }
77
+
70
78
/**
71
79
* Generate a link for a given outlet identifier and optional params.
72
80
*
0 commit comments