Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routerlink works without anchor tag

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 ?

like image 593
CodeHip Avatar asked Mar 27 '18 06:03

CodeHip


People also ask

What is difference between routerLink and href?

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.

Can I use routerLink on button?

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.

Does routerLink work on Div?

Yes it can be attached to div tag, your route is probably wrong try add / in front of route.

What is the difference between routerLink and router navigate?

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.


1 Answers

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.

like image 164
ForestG Avatar answered Sep 30 '22 17:09

ForestG