fix(router): NavigatonError and NavigationCancel should be emitted after resetting the URL (#20803)

PR Close #20803
This commit is contained in:
vsavkin
2017-12-05 11:34:34 -05:00
committed by Jason Aden
parent d41d2c460a
commit d8cc09b76c
2 changed files with 106 additions and 6 deletions

View File

@ -745,12 +745,14 @@ export class Router {
},
(e: any) => {
if (isNavigationCancelingError(e)) {
this.resetUrlToCurrentUrlTree();
this.navigated = true;
this.resetStateAndUrl(storedState, storedUrl, rawUrl);
(this.events as Subject<Event>)
.next(new NavigationCancel(id, this.serializeUrl(url), e.message));
resolvePromise(false);
} else {
this.resetStateAndUrl(storedState, storedUrl, rawUrl);
(this.events as Subject<Event>)
.next(new NavigationError(id, this.serializeUrl(url), e));
try {
@ -759,15 +761,17 @@ export class Router {
rejectPromise(ee);
}
}
(this as{routerState: RouterState}).routerState = storedState;
this.currentUrlTree = storedUrl;
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
this.resetUrlToCurrentUrlTree();
});
});
}
private resetStateAndUrl(storedState: RouterState, storedUrl: UrlTree, rawUrl: UrlTree): void {
(this as{routerState: RouterState}).routerState = storedState;
this.currentUrlTree = storedUrl;
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
this.resetUrlToCurrentUrlTree();
}
private resetUrlToCurrentUrlTree(): void {
this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree));
}