fix(router): properly read and serialize query params
This splits out `path` and `query` into separate params for `location.go` and related methods so that we can handle them properly in both `PathLocationStrategy` and `HashLocationStrategy`. This handles the problem of not reading query params to populate `Location` on the initial page load. Closes #3957 Closes #4225 Closes #3784
This commit is contained in:
@ -7,6 +7,8 @@ export class SpyLocation implements Location {
|
||||
/** @internal */
|
||||
_path: string = '';
|
||||
/** @internal */
|
||||
_query: string = '';
|
||||
/** @internal */
|
||||
_subject: EventEmitter = new EventEmitter();
|
||||
/** @internal */
|
||||
_baseHref: string = '';
|
||||
@ -21,12 +23,15 @@ export class SpyLocation implements Location {
|
||||
|
||||
normalizeAbsolutely(url: string): string { return this._baseHref + url; }
|
||||
|
||||
go(url: string) {
|
||||
url = this.normalizeAbsolutely(url);
|
||||
if (this._path == url) {
|
||||
go(path: string, query: string = '') {
|
||||
path = this.normalizeAbsolutely(path);
|
||||
if (this._path == path && this._query == query) {
|
||||
return;
|
||||
}
|
||||
this._path = url;
|
||||
this._path = path;
|
||||
this._query = query;
|
||||
|
||||
var url = path + (query.length > 0 ? ('?' + query) : '');
|
||||
this.urlChanges.push(url);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,10 @@ export class MockLocationStrategy extends LocationStrategy {
|
||||
ObservableWrapper.callNext(this._subject, {'url': pathname});
|
||||
}
|
||||
|
||||
pushState(ctx: any, title: string, url: string): void {
|
||||
pushState(ctx: any, title: string, path: string, query: string): void {
|
||||
this.internalTitle = title;
|
||||
|
||||
var url = path + (query.length > 0 ? ('?' + query) : '');
|
||||
this.internalPath = url;
|
||||
this.urlChanges.push(url);
|
||||
}
|
||||
|
Reference in New Issue
Block a user