[英]Angular 2 Routing - Hide URL
I know that you can hide the URL when routing using this.router.navigate(["/Pages"], { skipLocationChange: true });
我知道您可以使用
this.router.navigate(["/Pages"], { skipLocationChange: true });
路由时隐藏URL this.router.navigate(["/Pages"], { skipLocationChange: true });
but when i use window.open("/Pages")
it has the URL. 但是当我使用
window.open("/Pages")
它具有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? 使用
window.open()
时,是否有任何隐藏URL的方法,或使用angular2路由器在新选项卡中打开URL的方法?
You can inject the Location
like this: 您可以这样注入
Location
:
constructor(private readonly location: Location) {
//...
}
And then in ngOnInit()
run this: 然后在
ngOnInit()
运行:
public ngOnInit(): void {
this.location.replaceState("/");
}
This replaced the URL in the browser with the URL you specify in replaceState()
. 这将浏览器中的URL替换为您在
replaceState()
指定的URL。
Found an easy way in the end. 最终找到了一种简单的方法。
history.pushState({},"Edit","http://localhost:4200/");
works fine for what im after. 对于之后的工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.