angular - [routerLink]="" VS href="javascript:void(0);" - Stack Overflow

If I want to add a dead link to an anchor tag because I want to use (click) instead then I can use eith

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

Which one is prefered to use? Is there any difference?

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

Which one is prefered to use? Is there any difference?

Share asked Jun 8, 2018 at 6:41 Casper NybroeCasper Nybroe 1,2093 gold badges26 silver badges49 bronze badges 7
  • 1 If it's a deadlink on which you bind click event, you don't need both. – ADreNaLiNe-DJ Commented Jun 8, 2018 at 6:44
  • I weren't using both - just one or the other. The question states which would be prefered to use. – Casper Nybroe Commented Jun 8, 2018 at 7:50
  • What i'm saying is that none is needed. ;) – ADreNaLiNe-DJ Commented Jun 8, 2018 at 8:35
  • So you mean "you don't need any" then? ;) But I agree - unless you want the styling for an anchor which is only added if you add the href or routerLink attribute to the tag. I know you can just create your own stylings but keeping the default styling just by adding one of the attributes makes perfect sense to me. :) – Casper Nybroe Commented Jun 8, 2018 at 8:56
  • This is what i mean. But making styling based on href attribute (or routerLink) is a bad practice. One should use class attribute or other kind of selector. ;) – ADreNaLiNe-DJ Commented Jun 8, 2018 at 9:29
 |  Show 2 more ments

1 Answer 1

Reset to default 7
[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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745054921a4608603.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信