24

How to open a new browser Tab , if using router.navigate .

this.router.navigate([]).then(result => { window.location.href = link; });
CodeMan
  • 1,941
  • 6
  • 26
  • 44
  • Possible duplicate of [Angular 2 Routing run in new tab](https://stackoverflow.com/questions/41355830/angular-2-routing-run-in-new-tab) – Smokey Dawson May 25 '18 at 04:21

7 Answers7

61

Try this one.

this.router.navigate([]).then(result => {  window.open(link, '_blank'); });
Manish Vadher
  • 1,524
  • 15
  • 14
6

currently i believe angular doesn't offer any method or service to do that so i've to use window object to open links in a new tab window.open(link, '_blank')

mkamranhamid
  • 583
  • 4
  • 18
2

this will open in new tab :

 this._router.navigate([]).then(result => {  window.open( `/customer/edit/${customer_id_param}`, '_blank'); });
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71
2

To navigate to a new tab, instead of calling navigate directly:

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

Use createUrlTree and serializeUrl, so you can build your URL with the same parameters used in navigate() but without navigating the current tab (only the new one):

 const link = this.router.serializeUrl(this.router.createUrlTree(routerCommands, { queryParams }));
 window.open(link, '_blank');
Rafael Cerávolo
  • 673
  • 6
  • 13
0
const reportUrl = this._router.createUrlTree(['/your-url/endpoint', 
{data:"Data to pass"}]).toString();
window.open(reportUrl, '_blank');

Try this

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

Esto deberia funcionar tambien en angular:

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

}

  • 1
    You are calling external url using window.open(). The question is about opening the router link in a new tab. – Nikhil May 02 '22 at 11:53