@ -48,7 +48,9 @@ export class HashLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.onHashChange(fn);
|
||||
}
|
||||
|
||||
getBaseHref(): string { return this._baseHref; }
|
||||
getBaseHref(): string {
|
||||
return this._baseHref;
|
||||
}
|
||||
|
||||
path(includeHash: boolean = false): string {
|
||||
// the hash value is always prefixed with a `#`
|
||||
@ -80,7 +82,11 @@ export class HashLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.replaceState(state, title, url);
|
||||
}
|
||||
|
||||
forward(): void { this._platformLocation.forward(); }
|
||||
forward(): void {
|
||||
this._platformLocation.forward();
|
||||
}
|
||||
|
||||
back(): void { this._platformLocation.back(); }
|
||||
back(): void {
|
||||
this._platformLocation.back();
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,9 @@ export class Location {
|
||||
* Reports the current state of the location history.
|
||||
* @returns The current value of the `history.state` object.
|
||||
*/
|
||||
getState(): unknown { return this._platformLocation.getState(); }
|
||||
getState(): unknown {
|
||||
return this._platformLocation.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the given path and compares to the current normalized path.
|
||||
@ -173,12 +175,16 @@ export class Location {
|
||||
/**
|
||||
* Navigates forward in the platform's history.
|
||||
*/
|
||||
forward(): void { this._platformStrategy.forward(); }
|
||||
forward(): void {
|
||||
this._platformStrategy.forward();
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates back in the platform's history.
|
||||
*/
|
||||
back(): void { this._platformStrategy.back(); }
|
||||
back(): void {
|
||||
this._platformStrategy.back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a URL change listener. Use to catch updates performed by the Angular
|
||||
@ -188,7 +194,9 @@ export class Location {
|
||||
*/
|
||||
onUrlChange(fn: (url: string, state: unknown) => void) {
|
||||
this._urlChangeListeners.push(fn);
|
||||
this.subscribe(v => { this._notifyUrlChangeListeners(v.url, v.state); });
|
||||
this.subscribe(v => {
|
||||
this._notifyUrlChangeListeners(v.url, v.state);
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -126,9 +126,13 @@ export class PathLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.onHashChange(fn);
|
||||
}
|
||||
|
||||
getBaseHref(): string { return this._baseHref; }
|
||||
getBaseHref(): string {
|
||||
return this._baseHref;
|
||||
}
|
||||
|
||||
prepareExternalUrl(internal: string): string { return joinWithSlash(this._baseHref, internal); }
|
||||
prepareExternalUrl(internal: string): string {
|
||||
return joinWithSlash(this._baseHref, internal);
|
||||
}
|
||||
|
||||
path(includeHash: boolean = false): string {
|
||||
const pathname =
|
||||
@ -147,7 +151,11 @@ export class PathLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.replaceState(state, title, externalUrl);
|
||||
}
|
||||
|
||||
forward(): void { this._platformLocation.forward(); }
|
||||
forward(): void {
|
||||
this._platformLocation.forward();
|
||||
}
|
||||
|
||||
back(): void { this._platformLocation.back(); }
|
||||
back(): void {
|
||||
this._platformLocation.back();
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,9 @@ export interface LocationChangeEvent {
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export interface LocationChangeListener { (event: LocationChangeEvent): any; }
|
||||
export interface LocationChangeListener {
|
||||
(event: LocationChangeEvent): any;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -101,8 +103,8 @@ export interface LocationChangeListener { (event: LocationChangeEvent): any; }
|
||||
useFactory: createBrowserPlatformLocation,
|
||||
})
|
||||
export class BrowserPlatformLocation extends PlatformLocation {
|
||||
public readonly location !: Location;
|
||||
private _history !: History;
|
||||
public readonly location!: Location;
|
||||
private _history!: History;
|
||||
|
||||
constructor(@Inject(DOCUMENT) private _doc: any) {
|
||||
super();
|
||||
@ -112,11 +114,13 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
// This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
|
||||
/** @internal */
|
||||
_init() {
|
||||
(this as{location: Location}).location = getDOM().getLocation();
|
||||
(this as {location: Location}).location = getDOM().getLocation();
|
||||
this._history = getDOM().getHistory();
|
||||
}
|
||||
|
||||
getBaseHrefFromDOM(): string { return getDOM().getBaseHref(this._doc) !; }
|
||||
getBaseHrefFromDOM(): string {
|
||||
return getDOM().getBaseHref(this._doc)!;
|
||||
}
|
||||
|
||||
onPopState(fn: LocationChangeListener): void {
|
||||
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('popstate', fn, false);
|
||||
@ -126,14 +130,30 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
|
||||
}
|
||||
|
||||
get href(): string { return this.location.href; }
|
||||
get protocol(): string { return this.location.protocol; }
|
||||
get hostname(): string { return this.location.hostname; }
|
||||
get port(): string { return this.location.port; }
|
||||
get pathname(): string { return this.location.pathname; }
|
||||
get search(): string { return this.location.search; }
|
||||
get hash(): string { return this.location.hash; }
|
||||
set pathname(newPath: string) { this.location.pathname = newPath; }
|
||||
get href(): string {
|
||||
return this.location.href;
|
||||
}
|
||||
get protocol(): string {
|
||||
return this.location.protocol;
|
||||
}
|
||||
get hostname(): string {
|
||||
return this.location.hostname;
|
||||
}
|
||||
get port(): string {
|
||||
return this.location.port;
|
||||
}
|
||||
get pathname(): string {
|
||||
return this.location.pathname;
|
||||
}
|
||||
get search(): string {
|
||||
return this.location.search;
|
||||
}
|
||||
get hash(): string {
|
||||
return this.location.hash;
|
||||
}
|
||||
set pathname(newPath: string) {
|
||||
this.location.pathname = newPath;
|
||||
}
|
||||
|
||||
pushState(state: any, title: string, url: string): void {
|
||||
if (supportsState()) {
|
||||
@ -151,11 +171,17 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
}
|
||||
}
|
||||
|
||||
forward(): void { this._history.forward(); }
|
||||
forward(): void {
|
||||
this._history.forward();
|
||||
}
|
||||
|
||||
back(): void { this._history.back(); }
|
||||
back(): void {
|
||||
this._history.back();
|
||||
}
|
||||
|
||||
getState(): unknown { return this._history.state; }
|
||||
getState(): unknown {
|
||||
return this._history.state;
|
||||
}
|
||||
}
|
||||
|
||||
export function supportsState(): boolean {
|
||||
|
Reference in New Issue
Block a user