javascript - When should I use Link over NavLink? - Stack Overflow

With reference to React Router v4 <NavLink> vs <Link> benefits and the official documentati

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?

Share Improve this question asked Feb 13, 2021 at 12:26 thegreatjedithegreatjedi 3,0485 gold badges34 silver badges56 bronze badges 1
  • 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 a NavLink. this is the main difference as I thought. – Abdelmonaem Shahat Commented Feb 13, 2021 at 12:30
Add a ment  | 

1 Answer 1

Reset to default 6

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

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

相关推荐

  • javascript - When should I use Link over NavLink? - Stack Overflow

    With reference to React Router v4 <NavLink> vs <Link> benefits and the official documentati

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信