2017-03-24 206 views
2

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

当使用window.open()或使用angular2路由器在新选项卡中打开URL时,有什么方法可以隐藏URL吗?

回答

0

最后找到了一个简单的方法。 history.pushState({},"Edit","http://localhost:4200/");适用于以后的IM。

1

,你可以注入Location这样的:

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

然后在ngOnInit()运行以下命令:

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

这取代了网址与您在replaceState()指定URL的浏览器。