admin管理员组文章数量:1406926
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 useclass
attribute or other kind of selector. ;) – ADreNaLiNe-DJ Commented Jun 8, 2018 at 9:29
1 Answer
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.
本文标签: angularrouterLinkquotquot VS hrefquotjavascriptvoid(0)quotStack Overflow
版权声明:本文标题:angular - [routerLink]="" VS href="javascript:void(0);" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745054921a2639870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论