When Should I Use Link Over Navlink?
With reference to React Router v4 vs benefits and the official documentation, NavLink is a variant of Link that allows you to apply styling attributes
Solution 1:
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.
Post a Comment for "When Should I Use Link Over Navlink?"