Using Angular Router, I want to navigate to another url without adding it to the browser history.
this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);
Can I do it with only Angular?
Using Angular Router, I want to navigate to another url without adding it to the browser history.
this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);
Can I do it with only Angular?
Thanks to NavigationExtras you can now use replaceUrl: boolean
inside navigate()
This will replace the current url, and the new URL will update in the address bar:
this.router.navigate([`/somewhere`], { replaceUrl: true });
That way when you press back it will not remember the previous page in the history.
As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange
this.router.replaceUrl('path')
skipLocationChange
Navigates without pushing a new state into history.
this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });
Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange
replaceUrl
instead of skipLocationChange
. It's also an option of NavigationExtras
. –
Prizefight © 2022 - 2024 — McMap. All rights reserved.