3
3
* @module vanilla
4
4
*/ /** */
5
5
import { isDefined } from "../common/index" ;
6
- import { LocationServices } from "../common/coreservices" ;
6
+ import { LocationServices , LocationConfig } from "../common/coreservices" ;
7
7
import { splitQuery , trimHashVal , getParams , locationPluginFactory } from "./utils" ;
8
8
import { LocationPlugin } from "./interface" ;
9
9
import { UIRouter } from "../router" ;
@@ -18,21 +18,22 @@ import { BrowserLocationConfig } from "./browserLocationConfig";
18
18
*/
19
19
export class PushStateLocationService implements LocationServices , Disposable {
20
20
private _listeners : Function [ ] = [ ] ;
21
- private _hashPrefix = "" ;
22
21
private _location : Location ;
23
22
private _history : History ;
23
+ private _config : LocationConfig ;
24
24
25
- constructor ( public router : UIRouter ) {
25
+ constructor ( router : UIRouter ) {
26
26
this . _location = location ;
27
27
this . _history = history ;
28
+ this . _config = router . urlService . config ;
28
29
} ;
29
30
30
31
hash ( ) {
31
32
return trimHashVal ( this . _location . hash ) ;
32
33
}
33
34
34
35
path ( ) {
35
- let base = this . router . urlConfig . baseHref ( ) ;
36
+ let base = this . _config . baseHref ( ) ;
36
37
let path = this . _location . pathname ;
37
38
let idx = path . indexOf ( base ) ;
38
39
if ( idx !== 0 ) throw new Error ( `current url: ${ path } does not start with <base> tag ${ base } ` ) ;
@@ -45,7 +46,7 @@ export class PushStateLocationService implements LocationServices, Disposable {
45
46
46
47
setUrl ( url : string , replace : boolean = false ) {
47
48
if ( isDefined ( url ) ) {
48
- let fullUrl = this . router . urlConfig . baseHref ( ) + url ;
49
+ let fullUrl = this . _config . baseHref ( ) + url ;
49
50
if ( replace ) this . _history . replaceState ( null , null , fullUrl ) ;
50
51
else this . _history . pushState ( null , null , fullUrl ) ;
51
52
}
@@ -56,23 +57,12 @@ export class PushStateLocationService implements LocationServices, Disposable {
56
57
return pushTo ( this . _listeners , ( ) => window . removeEventListener ( "popstate" , cb ) ) ;
57
58
}
58
59
59
- html5Mode ( ) {
60
- return true ;
61
- }
62
-
63
- hashPrefix ( newprefix ?: string ) : string {
64
- if ( isDefined ( newprefix ) ) {
65
- this . _hashPrefix = newprefix ;
66
- }
67
- return this . _hashPrefix ;
68
- }
69
-
70
60
dispose ( router : UIRouter ) {
71
61
deregAll ( this . _listeners ) ;
72
62
}
73
- } ;
63
+ }
74
64
75
65
/** A `UIRouterPlugin` that gets/sets the current location using the browser's `location` and `history` apis */
76
66
export const pushStateLocationPlugin : ( router : UIRouter ) => LocationPlugin =
77
- locationPluginFactory ( "vanilla.pushStateLocation" , PushStateLocationService , BrowserLocationConfig ) ;
67
+ locationPluginFactory ( "vanilla.pushStateLocation" , true , PushStateLocationService , BrowserLocationConfig ) ;
78
68
0 commit comments