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?
Angular provides extensive set of navigation feature to accommodate simple scenario to complex scenario. The process of defining navigation element and the corresponding view is called Routing. Angular provides a separate module, RouterModule to set up the navigation in the Angular application.
The two asterisks, ** , indicate to Angular that this routes definition is a wildcard route. For the component property, you can define any component in your application.
skipLocationChange: boolean. You can change the route, without changing the URL in the browser. This Navigates to a new URL without pushing a new state into history.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With