I just noticed that routerLink works on any element e.g on divs, mat-card, mat-title, etc, without needing to wrap an anchor tag around.
Is that okay / safe to do so or you need to use it with the anchor ? Maybe it can have some bad consequences later if doing so ?
Href is the basic attribute provided by Html to navigate through pages which reloads the page on click. routerLink is the attribute provided by angular to navigate to different components without reloading the page.
Using Router linksAfter Angular v4 we can directly add a routerLink attribute on the anchor tag or button. Consider the following template, where routerLink attribute added to the anchor tag. The routerLink directive on the anchor tags give the router control over those elements.
Yes it can be attached to div tag, your route is probably wrong try add / in front of route.
router. navigate should navigate to exactly the same url if the same arguments are specified. routerLink works on any element, not only on <a> and <button> . Another main difference is, that for relative navigation, you need to pass the route to the relativeTo parameter with this.
I think routerLink.navigate is a direcitve which listens on an onclick event.
So as long as using onClick is safe, you are safe to use routerLink too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With