fix(router): preserve fragment on initial load
This commit is contained in:
parent
a620f95891
commit
90295e3252
|
@ -77,7 +77,7 @@ export class HashLocationStrategy extends LocationStrategy {
|
|||
|
||||
getBaseHref(): string { return this._baseHref; }
|
||||
|
||||
path(): string {
|
||||
path(includeHash: boolean = false): string {
|
||||
// the hash value is always prefixed with a `#`
|
||||
// and if it is empty then it will stay empty
|
||||
var path = this._platformLocation.hash;
|
||||
|
|
|
@ -70,14 +70,19 @@ export class Location {
|
|||
var browserBaseHref = this._platformStrategy.getBaseHref();
|
||||
this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref));
|
||||
this._platformStrategy.onPopState((ev) => {
|
||||
ObservableWrapper.callEmit(this._subject, {'url': this.path(), 'pop': true, 'type': ev.type});
|
||||
ObservableWrapper.callEmit(
|
||||
this._subject, {'url': this.path(true), 'pop': true, 'type': ev.type});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normalized URL path.
|
||||
*/
|
||||
path(): string { return this.normalize(this._platformStrategy.path()); }
|
||||
// TODO: vsavkin. Remove the boolean flag and always include hash once the deprecated router is
|
||||
// removed.
|
||||
path(includeHash: boolean = false): string {
|
||||
return this.normalize(this._platformStrategy.path(includeHash));
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the given path and compares to the current normalized path.
|
||||
|
|
|
@ -28,7 +28,7 @@ import {UrlChangeListener} from './platform_location';
|
|||
* @stable
|
||||
*/
|
||||
export abstract class LocationStrategy {
|
||||
abstract path(): string;
|
||||
abstract path(includeHash: boolean): string;
|
||||
abstract prepareExternalUrl(internal: string): string;
|
||||
abstract pushState(state: any, title: string, url: string, queryParams: string): void;
|
||||
abstract replaceState(state: any, title: string, url: string, queryParams: string): void;
|
||||
|
|
|
@ -98,9 +98,11 @@ export class PathLocationStrategy extends LocationStrategy {
|
|||
return Location.joinWithSlash(this._baseHref, internal);
|
||||
}
|
||||
|
||||
path(): string {
|
||||
return this._platformLocation.pathname +
|
||||
path(includeHash: boolean = false): string {
|
||||
const pathname = this._platformLocation.pathname +
|
||||
Location.normalizeQueryParams(this._platformLocation.search);
|
||||
const hash = this._platformLocation.hash;
|
||||
return hash && includeHash ? `${pathname}${hash}` : pathname;
|
||||
}
|
||||
|
||||
pushState(state: any, title: string, url: string, queryParams: string) {
|
||||
|
|
|
@ -32,7 +32,7 @@ export class MockLocationStrategy extends LocationStrategy {
|
|||
ObservableWrapper.callEmit(this._subject, new _MockPopStateEvent(this.path()));
|
||||
}
|
||||
|
||||
path(): string { return this.internalPath; }
|
||||
path(includeHash: boolean = false): string { return this.internalPath; }
|
||||
|
||||
prepareExternalUrl(internal: string): string {
|
||||
if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
|
||||
|
|
|
@ -123,7 +123,7 @@ export class Router {
|
|||
*/
|
||||
initialNavigation(): void {
|
||||
this.setUpLocationChangeListener();
|
||||
this.navigateByUrl(this.location.path());
|
||||
this.navigateByUrl(this.location.path(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue