Angular 2 Routing navigate 运行 in new tab(使用Angular Router navigate )

Angular 2 Routing navigate run in new tab(Use Angular Router naviagte )

如何打开新的浏览器选项卡,如果使用 router.navigate。

this.router.navigate([]).then(result => { window.location.href = link; });

试试这个。

this.router.navigate([]).then(result => {  window.open(link, '_blank'); });

目前我认为 angular 不提供任何方法或服务来做到这一点,所以我必须使用 window 对象在新选项卡中打开链接 window.open(link, '_blank')

window.open(window.location.href+"/yourRoute", '_blank');

这将在新标签页中打开:

 this._router.navigate([]).then(result => {  window.open( `/customer/edit/${customer_id_param}`, '_blank'); });

这也适用于 angular:

  abrirVentana() {
var URL = 'https://whosebug.com/';
window.open(URL, '_blank');

}

要导航到新选项卡,而不是直接调用导航:

this.router.navigate(routerCommands, { queryParams });

使用 createUrlTreeserializeUrl,这样您就可以使用在 navigate() 中使用的相同参数构建您的 URL 但是不导航当前选项卡(仅导航新选项卡):

 const link = this.router.serializeUrl(this.router.createUrlTree(routerCommands, { queryParams }));
 window.open(link, '_blank');