fix(router): replace state when path is equal to current path (#8766)
Same as 2bf21e1747
but for new router.
This also fixes an issue where when application loads it clears forward history
because Router constructor calls navigateByUrl which was causing a push state to happen.
This commit is contained in:

committed by
Miško Hevery

parent
84f859d7b2
commit
b2a7fd05cb
@ -151,7 +151,7 @@ export class Router {
|
||||
(change) => { this._navigate(this._urlSerializer.parse(change['url']), change['pop']); });
|
||||
}
|
||||
|
||||
private _navigate(url: UrlTree, pop?: boolean): Promise<void> {
|
||||
private _navigate(url: UrlTree, preventPushState?: boolean): Promise<void> {
|
||||
this._urlTree = url;
|
||||
return recognize(this._componentResolver, this._rootComponentType, url, this._routeTree)
|
||||
.then(currTree => {
|
||||
@ -160,8 +160,13 @@ export class Router {
|
||||
.then(updated => {
|
||||
if (updated) {
|
||||
this._routeTree = currTree;
|
||||
if (isBlank(pop) || !pop) {
|
||||
this._location.go(this._urlSerializer.serialize(this._urlTree));
|
||||
if (isBlank(preventPushState) || !preventPushState) {
|
||||
let path = this._urlSerializer.serialize(this._urlTree);
|
||||
if (this._location.isCurrentPathEqualTo(path)) {
|
||||
this._location.replaceState(path);
|
||||
} else {
|
||||
this._location.go(path);
|
||||
}
|
||||
}
|
||||
this._changes.emit(null);
|
||||
}
|
||||
|
Reference in New Issue
Block a user