Search code examples
htmlcssangularcss-selectorsrouterlink

Why is the [routerLink] directive selector defined as :not(a)[routerLink]?


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?


Solution

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