1

I have a div element or tr element and there is a router link on it.

Since it isnt an a tag, there is no option for right-clicking and "open in new tab" or strg + click for opening in new tab.

But i want to achieve this function, so if the user wants to open the link in new tab, he could do it like described. I can't change my tr into an a tag.

Is there any possiblity to get this functionality "open in new tab" without an a tag?

Emre Öztürk
  • 2,660
  • 4
  • 16
  • 19
  • Possible duplicate of [Angular 6 routerLink on a new tab](https://stackoverflow.com/questions/54483451/angular-6-routerlink-on-a-new-tab) – wentjun Jun 17 '19 at 09:08
  • No, i dont want, that it opens always in a tab. There should be the option with right click to open it on a new tab – Emre Öztürk Jun 17 '19 at 09:15

2 Answers2

3

href reload the page no need to use in SPA.

It only works on anchor tag to show menus when right-click use. like "open in new tab"

It can be used on a button.

you can use the code below for your purpose.

default open in new tab = target="_blank"

<a target="_blank" [routerLink]="'/edit/'+prop.id"> 

<a [routerLink]="'/edit/'+prop.id">
Hassan Ali
  • 994
  • 6
  • 22
0

No, only links have the href attribute.

From there, two options :

  • Create a link on the fly
  • append a link as the direct child of your element

Create a link on the fly :

<tr (click)="inNewTab()">
inNewTab() {
  const link = document.createElement('a');
  link.href = '';
  link.target = '_blank';
  link.click();
  link.remove();
}

Use a link as the direct element :

<tr>
  <a href="" target="_blank">...</a>
</tr>
tr > a[target="_blank"] {
  display: block;
  height: 100%;
  width: 100%;
}