-
Notifications
You must be signed in to change notification settings - Fork 58
/
browserLocationConfig.ts
52 lines (41 loc) · 1.28 KB
/
browserLocationConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @internalapi
* @module vanilla
*/
/** */
import { isDefined } from '../common/predicates';
import { LocationConfig } from '../common/coreservices';
/** A `LocationConfig` that delegates to the browser's `location` object */
export class BrowserLocationConfig implements LocationConfig {
private _baseHref = undefined;
private _hashPrefix = '';
constructor(router?, private _isHtml5 = false) { }
port(): number {
if (location.port) {
return Number(location.port);
}
return this.protocol() === 'https' ? 443 : 80;
}
protocol(): string {
return location.protocol.replace(/:/g, '');
}
host(): string {
return location.hostname;
}
html5Mode(): boolean {
return this._isHtml5;
}
hashPrefix(): string;
hashPrefix(newprefix?: string): string {
return isDefined(newprefix) ? this._hashPrefix = newprefix : this._hashPrefix;
}
baseHref(href?: string): string {
return isDefined(href) ? this._baseHref = href :
isDefined(this._baseHref) ? this._baseHref : this.applyDocumentBaseHref();
}
applyDocumentBaseHref() {
const baseTag: HTMLBaseElement = document.getElementsByTagName('base')[0];
return this._baseHref = baseTag ? baseTag.href.substr(location.origin.length) : location.pathname || '/';
}
dispose() {}
}