Angular 7 Router - Navigate without adding to the history

Alex York picture Alex York · Jan 3, 2019 · Viewed 10.6k times · Source

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?

Answer

Elron picture Elron · Sep 26, 2019

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.