Search code examples
angularrouterlink

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.


Solution

  • 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>