我有一个角度2组件,需要导航到另一条路线但在不同的浏览器标签中。下面的代码在同一浏览器选项卡中导航。
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
templateUrl: 'quotes-edit.component.html'
})
export class QuoteComponent {
constructor(private router: Router) {
}
this.router.navigate(['quote/add']);
}
答案 0 :(得分:1)
Angular应用程序是SPA(单页应用程序),这意味着路由器只不过是模拟路由更改的模块而已。您可以在像这样的其他标签中的另一条路线中打开重定向
/**
* Open url in a new tab
*/
navigateToNewTab(): void {
// Here you can get the url
const { protocol, host } = window.location;
// Or use the router
// this.router.url
const path = '...';
const url = `${protocol}//${host}/${path}`;
window.open(url,'_blank');
}
答案 1 :(得分:0)
您不会为此使用角度路由器,而是可以制作具有以下功能的功能
openinbrowserclicked(url) {
window.open(
'url',
'_blank',
'toolbar=no,resizable=yes,scrollbars=yes'
);
}