|
1 | 1 | /**
|
2 | 2 | * @internalapi
|
3 | 3 | * @module vanilla
|
4 |
| - */ /** */ |
| 4 | + */ |
| 5 | +/** */ |
5 | 6 | import { isDefined } from "../common/index";
|
6 | 7 | import { LocationServices } from "../common/coreservices";
|
7 | 8 | import { splitHash, splitQuery, trimHashVal, getParams, locationPluginFactory, buildUrl } from "./utils";
|
8 | 9 | import { UIRouter } from "../router";
|
9 |
| -import { LocationPlugin } from "./interface"; |
| 10 | +import { LocationPlugin, LocationLike, HistoryLike } from "./interface"; |
10 | 11 | import { pushTo, deregAll } from "../common/common";
|
11 | 12 | import { Disposable } from "../interface";
|
12 | 13 | import { BrowserLocationConfig } from "./browserLocationConfig";
|
13 | 14 |
|
14 | 15 | /** A `LocationServices` that uses the browser hash "#" to get/set the current location */
|
15 | 16 | export class HashLocationService implements LocationServices, Disposable {
|
16 | 17 | private _listeners: Function[] = [];
|
| 18 | + _location: LocationLike; |
| 19 | + _history: HistoryLike; |
17 | 20 |
|
18 |
| - hash = () => splitHash(trimHashVal(location.hash))[1]; |
19 |
| - path = () => splitHash(splitQuery(trimHashVal(location.hash))[0])[0]; |
20 |
| - search = () => getParams(splitQuery(splitHash(trimHashVal(location.hash))[0])[1]); |
| 21 | + _getHash = () => trimHashVal(this._location.hash); |
| 22 | + _setHash = (val) => this._location.hash = val; |
| 23 | + |
| 24 | + hash = () => splitHash(this._getHash())[1]; |
| 25 | + path = () => splitHash(splitQuery(this._getHash())[0])[0]; |
| 26 | + search = () => getParams(splitQuery(splitHash(this._getHash())[0])[1]); |
21 | 27 |
|
22 | 28 | url(url?: string, replace: boolean = true): string {
|
23 |
| - if (isDefined(url)) location.hash = url; |
| 29 | + if (isDefined(url)) this._setHash(url); |
24 | 30 | return buildUrl(this);
|
25 | 31 | }
|
26 | 32 |
|
|
0 commit comments