Angular 2: Prevent router from adding to history

It turns out there is a built-in way for Angular 2's routing to skip adding a state to the history. We actually found it checking through random properties inside the intellisense of the editor.

Our routing code just had to go from:

this.router.navigate([`/myPage/${this.Id}`], { relativeTo: this.route });

to:

this.router.navigate([`/myPage/${this.Id}`], { relativeTo: this.route, skipLocationChange: true });


In addition, there is an option in NavigationExtras, which allows to replace current state in history with new one:

this.router.navigate(['/view'], {replaceUrl: true});