fix(router): do not call location.go when skipping a navigation (#19463)

Closes #18036

PR Close #19463
This commit is contained in:
vsavkin
2017-09-29 11:03:16 -04:00
committed by Chuck Jazdzewski
parent b67d574a95
commit fdfa31798b
2 changed files with 84 additions and 26 deletions

View File

@ -580,10 +580,9 @@ export class Router {
}
private runNavigate(
url: UrlTree, rawUrl: UrlTree, shouldPreventPushState: boolean, shouldReplaceUrl: boolean,
id: number, precreatedState: RouterStateSnapshot|null): Promise<boolean> {
url: UrlTree, rawUrl: UrlTree, skipLocationChange: boolean, replaceUrl: boolean, id: number,
precreatedState: RouterStateSnapshot|null): Promise<boolean> {
if (id !== this.navigationId) {
this.location.go(this.urlSerializer.serialize(this.currentUrlTree));
(this.events as Subject<Event>)
.next(new NavigationCancel(
id, this.serializeUrl(url),
@ -705,9 +704,9 @@ export class Router {
(this as{routerState: RouterState}).routerState = state;
if (!shouldPreventPushState) {
if (!skipLocationChange) {
const path = this.urlSerializer.serialize(this.rawUrlTree);
if (this.location.isCurrentPathEqualTo(path) || shouldReplaceUrl) {
if (this.location.isCurrentPathEqualTo(path) || replaceUrl) {
this.location.replaceState(path);
} else {
this.location.go(path);
@ -755,14 +754,13 @@ export class Router {
(this as{routerState: RouterState}).routerState = storedState;
this.currentUrlTree = storedUrl;
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
this.location.replaceState(this.serializeUrl(this.rawUrlTree));
this.resetUrlToCurrentUrlTree();
});
});
}
private resetUrlToCurrentUrlTree(): void {
const path = this.urlSerializer.serialize(this.rawUrlTree);
this.location.replaceState(path);
this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree));
}
}