admin管理员组文章数量:1421483
With reference to React Router v4 <NavLink> vs <Link> benefits and the official documentation, NavLink
is a variant of Link
that allows you to apply styling attributes when it is the active link. These styling attributes do not appear to be mandatory, and I haven't found anything describing the pros of using Link
.
If that's the case, why not just use NavLink
everywhere? Are there any reasons to choosing Link
over NavLink
? Functionality perhaps, or better performance?
With reference to React Router v4 <NavLink> vs <Link> benefits and the official documentation, NavLink
is a variant of Link
that allows you to apply styling attributes when it is the active link. These styling attributes do not appear to be mandatory, and I haven't found anything describing the pros of using Link
.
If that's the case, why not just use NavLink
everywhere? Are there any reasons to choosing Link
over NavLink
? Functionality perhaps, or better performance?
-
cause you might just need a link backing to the home page you don't need to apply any active class on it so u just make it a
Link
, not aNavLink
. this is the main difference as I thought. – Abdelmonaem Shahat Commented Feb 13, 2021 at 12:30
1 Answer
Reset to default 6Well actually, the main difference between these two's is a class attribute. When we use the NavLink as a tag, it automatically inherit an active class when clicked. On the other hand, the Link tag does now have an active class when clicked.
When should I use the NavLink?
Just as the name implies 'NavLink', we use it mostly on navigation bars. This is because the active class permits us to define our custom styling in the App.css stylesheet. As such, we can use it to style our active buttons which in notify the use on which page he/she is currently on.
When should I use the Link?
The Link tag can be used where we want to do just some routing with no special effect. For instance; we can use the Link tag for scroll-to-top button, add to card buttons, submit button and more.
本文标签: javascriptWhen should I use Link over NavLinkStack Overflow
版权声明:本文标题:javascript - When should I use Link over NavLink? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745323761a2653498.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论