Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable "ctrl+click" with "routerLink" in Angular

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.

like image 970
Marvin Ericson Avatar asked Dec 14 '22 14:12

Marvin Ericson


2 Answers

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>
like image 85
user184994 Avatar answered Dec 28 '22 11:12

user184994


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"
like image 38
Raphaël Balet Avatar answered Dec 28 '22 11:12

Raphaël Balet