Routing Prevention routerLink Changing Routes with Click Event Handler

My angular application contains an anchor tag that has an associated handler routerLinkand click:

<a [routerLink]="/abc" (click)="onClick"> </a>

I would like it to routerLinkbe used when the user right-clicks and selects "Open in new tab."

The handler clickshould start if the user just left-clicks the link. In this case, I do NOT want to routerLinkcause a route change.

Inside my click handler, I tried to abort the click event, i.e.

public onClick(event: MouseEvent): {
    // Was hoping this would do it...
    event.preventDefault();
    // .. clutching at straws
    event.stopPropagation();
    // .. oh dear oh dear. Still not working
    event.stopImmediatePropagation();
}

routerLink /abc. click routerLink?

+4

Source: https://habr.com/ru/post/1652373/


All Articles