繁体   English   中英

Angular 2路由-隐藏URL

[英]Angular 2 Routing - Hide URL

我知道您可以使用this.router.navigate(["/Pages"], { skipLocationChange: true });路由时隐藏URL this.router.navigate(["/Pages"], { skipLocationChange: true }); 但是当我使用window.open("/Pages")它具有URL。

使用window.open()时,是否有任何隐藏URL的方法,或使用angular2路由器在新选项卡中打开URL的方法?

您可以这样注入Location

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

然后在ngOnInit()运行:

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

这将浏览器中的URL替换为您在replaceState()指定的URL。

最终找到了一种简单的方法。 history.pushState({},"Edit","http://localhost:4200/"); 对于之后的工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM