20

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

this.router.navigate([]).then(result => { window.location.href = link; });
CodeMan
  • 1,841
  • 5
  • 24
  • 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

6 Answers6

55

Try this one.

this.router.navigate([]).then(result => {  window.open(link, '_blank'); });
Manish Vadher
  • 1,416
  • 14
  • 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
  • 495
  • 3
  • 15
2

this will open in new tab :

 this._router.navigate([]).then(result => {  window.open( `/customer/edit/${customer_id_param}`, '_blank'); });
Saurabh Mistry
  • 11,077
  • 4
  • 41
  • 64
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
  • 556
  • 4
  • 11
-1
window.open(window.location.href+"/yourRoute", '_blank');
-3

Esto deberia funcionar tambien en angular:

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

}

  • 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