问题
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?
回答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()
.
回答2:
Found an easy way in the end. history.pushState({},"Edit","http://localhost:4200/");
works fine for what im after.
来源:https://stackoverflow.com/questions/42998677/angular-2-routing-hide-url