Skip to content

Commit 588dd99

Browse files
docs(Transition): Document UrlRouter as internal API
Relates to angular-ui/ui-router#3262 (comment)
1 parent fc571a2 commit 588dd99

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

src/url/urlRouter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ defaultRuleSortFn = composeSort(
5353
*
5454
* ### Deprecation warning:
5555
* This class is now considered to be an internal API
56-
* For configuring URL rules, use the [[UrlRulesApi]] which can be found on [[UrlService.rules]].
56+
* Use the [[UrlService]] instead.
57+
* For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]].
5758
*
5859
* This class updates the URL when the state changes.
5960
* It also responds to changes in the URL.

src/vanilla/hashLocation.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
/**
22
* @internalapi
33
* @module vanilla
4-
*/ /** */
4+
*/
5+
/** */
56
import { isDefined } from "../common/index";
67
import { LocationServices } from "../common/coreservices";
78
import { splitHash, splitQuery, trimHashVal, getParams, locationPluginFactory, buildUrl } from "./utils";
89
import { UIRouter } from "../router";
9-
import { LocationPlugin } from "./interface";
10+
import { LocationPlugin, LocationLike, HistoryLike } from "./interface";
1011
import { pushTo, deregAll } from "../common/common";
1112
import { Disposable } from "../interface";
1213
import { BrowserLocationConfig } from "./browserLocationConfig";
1314

1415
/** A `LocationServices` that uses the browser hash "#" to get/set the current location */
1516
export class HashLocationService implements LocationServices, Disposable {
1617
private _listeners: Function[] = [];
18+
_location: LocationLike;
19+
_history: HistoryLike;
1720

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]);
2127

2228
url(url?: string, replace: boolean = true): string {
23-
if (isDefined(url)) location.hash = url;
29+
if (isDefined(url)) this._setHash(url);
2430
return buildUrl(this);
2531
}
2632

src/vanilla/interface.ts

+13
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ export interface ServicesPlugin extends UIRouterPlugin {
1515
$q: $QLike,
1616
$injector: $InjectorLike
1717
}
18+
19+
export interface LocationLike {
20+
hash: string;
21+
pathname: string;
22+
search: string;
23+
}
24+
25+
export interface HistoryLike {
26+
back(distance?: any): void;
27+
forward(distance?: any): void;
28+
pushState(statedata: any, title?: string, url?: string): void;
29+
replaceState(statedata: any, title?: string, url?: string): void;
30+
}

src/vanilla/pushStateLocation.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { isDefined } from "../common/index";
66
import { LocationServices, LocationConfig } from "../common/coreservices";
77
import { splitQuery, trimHashVal, getParams, locationPluginFactory, buildUrl } from "./utils";
8-
import { LocationPlugin } from "./interface";
8+
import { LocationPlugin, HistoryLike, LocationLike } from "./interface";
99
import { UIRouter } from "../router";
1010
import { pushTo, deregAll } from "../common/common";
1111
import { Disposable } from "../interface";
@@ -18,9 +18,9 @@ import { BrowserLocationConfig } from "./browserLocationConfig";
1818
*/
1919
export class PushStateLocationService implements LocationServices, Disposable {
2020
private _listeners: Function[] = [];
21-
private _location: Location;
22-
private _history: History;
23-
private _config: LocationConfig;
21+
_location: LocationLike;
22+
_history: HistoryLike;
23+
_config: LocationConfig;
2424

2525
constructor(router: UIRouter) {
2626
this._location = location;

0 commit comments

Comments
 (0)