2

I know that you can hide the URL when routing using this.router.navigate(["/Pages"], { skipLocationChange: true }); but when i use window.open("/Pages") it has the URL.

Is there any way to hide the URL when using window.open() or a way to use the angular2 router to open the URL in a new tab?

mast3rd3mon
  • 8,229
  • 2
  • 22
  • 46

2 Answers2

1

You can inject the Location like this:

constructor(private readonly location: Location) {
    //...
}

And then in ngOnInit() run this:

public ngOnInit(): void {
    this.location.replaceState("/");
}

This replaced the URL in the browser with the URL you specify in replaceState().

Spitzbueb
  • 5,233
  • 1
  • 20
  • 38
-2

Found an easy way in the end. history.pushState({},"Edit","http://localhost:4200/"); works fine for what im after.

mast3rd3mon
  • 8,229
  • 2
  • 22
  • 46