5

In Angular, if you use this:

<div routerLink="/home"> <img src="..." /> </div>

When I press on image it routes perfect, I want to press ctrl+click to open this link in new tab, or drag this image to a new tab, but when I press ctrl+click it opened in same page, and if I drag it, the image opened in new tab not the link, I tried to use target="_blank" but it is not working.

Marvin Ericson
  • 239
  • 2
  • 7
  • 20

3 Answers3

12

Instead of using a div tag, you will need to use an a tag so that the browser knows to treat it like a link.

<a routerLink="/home"> <img src="..." /> </a>
user184994
  • 17,791
  • 1
  • 46
  • 52
7

You can add a link role to the div

<div routerLink="/home" role="link">
  <img src="..." /> 
</div>

If you want to enable the "ctrl+click" behavior and don't :

  • want to change your div tag to an a tag
  • Use target="_blank"
Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78
0

Seems you are facing similar issue mentioned here , i would recommend you to try something like this,

<a routerLinkActive="active" [routerLink]="['/home']" ><img src="..." /></a>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396