Reputation: 1199
If I want to add a dead link to an anchor tag because I want to use (click) instead then I can use either [routerLink]=""
or href="javascript:void(0);"
. Both has the same effect and I see no difference in browser compatibility.
Which one is prefered to use? Is there any difference?
Upvotes: 1
Views: 3712
Reputation: 86740
[routerLink]=""
What this line does it, It will redirect to your home route/root route, whereas
href="javascript:void(0);"
The void operator evaluates the given expression and then returns undefined.
for more information read out here -
* What does “javascript:void(0)” mean?
Apart from this if you want to make it a
as deadlink just pass event through the click event and use event.preventDefault()
which will stop default action of anchor tag will execute what you want to do.
Upvotes: 7