3

In the Angular documentation, the routerLink directive selectors is defined as :

:not(a)[routerLink]

To my knowledge, this means "all non <a> tags that have the attribute routerLink".

However, later in the same documentation they show examples of routerLink being used with <a> tags, for example:

<a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
  link to user component
</a>

Is this an error in the documentation or is there something I don't know about selectors?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • 2
    There are two directives RouterLink and RouterLinkWithHref https://github.com/angular/angular/blob/master/packages/router/src/directives/router_link.ts – yurzui Nov 09 '17 at 20:51

1 Answers1

2

To add on @yurzui comment,

two is needed as RouterLinkWithHref updates the href on the anchor tag, and you can have all the benifts of link tag like opening in new tab,

And if you are applying routerLink to non anchor tag RouterLink directive is used and there is no href to set.

Madhu Ranjan
  • 17,334
  • 7
  • 60
  • 69
  • Thanks for the explanation. I wish the documentation was more clear. Currently I am only able to find the `RouterLink` directive, not the `RouterLinkWithHref` – CodyBugstein Nov 09 '17 at 22:26
  • @CodyBugstein it's in the same file as https://github.com/angular/angular/blob/master/packages/router/src/directives/router_link.ts – Alfredo Osorio Nov 26 '18 at 06:10