@ -54,34 +54,40 @@ export class ServerPlatformLocation implements PlatformLocation {
|
||||
}
|
||||
}
|
||||
|
||||
getBaseHrefFromDOM(): string { return getDOM().getBaseHref(this._doc) !; }
|
||||
getBaseHrefFromDOM(): string {
|
||||
return getDOM().getBaseHref(this._doc)!;
|
||||
}
|
||||
|
||||
onPopState(fn: LocationChangeListener): void {
|
||||
// No-op: a state stack is not implemented, so
|
||||
// no events will ever come.
|
||||
}
|
||||
|
||||
onHashChange(fn: LocationChangeListener): void { this._hashUpdate.subscribe(fn); }
|
||||
onHashChange(fn: LocationChangeListener): void {
|
||||
this._hashUpdate.subscribe(fn);
|
||||
}
|
||||
|
||||
get url(): string { return `${this.pathname}${this.search}${this.hash}`; }
|
||||
get url(): string {
|
||||
return `${this.pathname}${this.search}${this.hash}`;
|
||||
}
|
||||
|
||||
private setHash(value: string, oldUrl: string) {
|
||||
if (this.hash === value) {
|
||||
// Don't fire events if the hash has not changed.
|
||||
return;
|
||||
}
|
||||
(this as{hash: string}).hash = value;
|
||||
(this as {hash: string}).hash = value;
|
||||
const newUrl = this.url;
|
||||
scheduleMicroTask(() => this._hashUpdate.next({
|
||||
type: 'hashchange', state: null, oldUrl, newUrl
|
||||
} as LocationChangeEvent));
|
||||
scheduleMicroTask(
|
||||
() => this._hashUpdate.next(
|
||||
{type: 'hashchange', state: null, oldUrl, newUrl} as LocationChangeEvent));
|
||||
}
|
||||
|
||||
replaceState(state: any, title: string, newUrl: string): void {
|
||||
const oldUrl = this.url;
|
||||
const parsedUrl = parseUrl(newUrl);
|
||||
(this as{pathname: string}).pathname = parsedUrl.pathname;
|
||||
(this as{search: string}).search = parsedUrl.search;
|
||||
(this as {pathname: string}).pathname = parsedUrl.pathname;
|
||||
(this as {search: string}).search = parsedUrl.search;
|
||||
this.setHash(parsedUrl.hash, oldUrl);
|
||||
}
|
||||
|
||||
@ -89,12 +95,18 @@ export class ServerPlatformLocation implements PlatformLocation {
|
||||
this.replaceState(state, title, newUrl);
|
||||
}
|
||||
|
||||
forward(): void { throw new Error('Not implemented'); }
|
||||
forward(): void {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
back(): void { throw new Error('Not implemented'); }
|
||||
back(): void {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
// History API isn't available on server, therefore return undefined
|
||||
getState(): unknown { return undefined; }
|
||||
getState(): unknown {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
|
Reference in New Issue
Block a user