How to open a route url in new tab in angular 2?

Viewed 8101

I am trying to open router.navigate(["/url"]) in new tab. If I give, target="_blank"in link, it opens a blank new page, without any data. Otherwise, it opens in same window with the data from server. I would link to achieve the same functionality in anew tab. How to achieve that?

Regards, Meenakshi Jyotsna

2 Answers

Angular doesn't support navigating to a new tab , please use window.open to do this

window.open(url, '_blank');

I have found luck with adding the following to a link to open in a new tab.

li(*ngFor="let link of listOfLinks")
.test-link
  a.menu-item(
    [href]="link.href"
    rel="noopener noreferrer"
    target="_blank"
    ) {{link.name}}

The rel="noopener no referrer" somehow allows the target="_blank to work, not 100% sure how, but give it a try!

Related