fix(router): apply APP_BASE_HREF when using PathLocationStrategy

Correctly initializes APP_BASE_HREF, and falls back to the `<base>` tag in the absence
of an APP_BASE_HREF provider.

Closes #5028
This commit is contained in:
Brian Ford
2015-11-17 10:47:59 -08:00
parent b571baab68
commit ac38812809
6 changed files with 78 additions and 74 deletions

View File

@ -18,7 +18,12 @@ export class MockLocationStrategy extends LocationStrategy {
path(): string { return this.internalPath; }
prepareExternalUrl(internal: string): string { return internal; }
prepareExternalUrl(internal: string): string {
if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
return this.internalBaseHref + internal.substring(1);
}
return this.internalBaseHref + internal;
}
simulateUrlPop(pathname: string): void {
ObservableWrapper.callNext(this._subject, {'url': pathname});
@ -29,7 +34,9 @@ export class MockLocationStrategy extends LocationStrategy {
var url = path + (query.length > 0 ? ('?' + query) : '');
this.internalPath = url;
this.urlChanges.push(url);
var external = this.prepareExternalUrl(url);
this.urlChanges.push(external);
}
onPopState(fn: (value: any) => void): void { ObservableWrapper.subscribe(this._subject, fn); }