Angular 2 Routing - Hide URL

不问归期 提交于 2019-12-22 18:29:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!