Besides the ability to set an "activeClassName" and "activeStyle" on NavLink, is there any reason to use NavLink over Link when creating links to other routes on non-navigational elements (ie. not main nav in header or footer) on your site that don't need an active state/class?
-
5I can't comment directly to TOUMI (because I don't have 50rep), so I'll add it here. `NavLink` keeps the proper focus on the page for accessibility. When using link, initial focus is lost on page load and you will also notice that tabbing through dropdowns also breaks when using `Link`. NavLink fixes this. – DJNorris Jul 11 '19 at 20:08
7 Answers
The official documentation is clear:
<NavLink>
A special version of the
<Link>
that will add styling attributes to the rendered element when it matches the current URL.
Thus, the answer is NO. There are no other reasons except the mentioned one.

- 3,081
- 2
- 28
- 32

- 87,526
- 38
- 249
- 254
When you need to use style or class attributes on active <Link>
, then you can use <NavLink>
Let see the example:
Link
<Link to="/">Home</Link>
NavLink
<NavLink to="/" activeClassName="active">Home</NavLink>

- 5,600
- 2
- 38
- 44
Link Component
It is used to create links which allow to navigate on different URLs and When we click on any of that particular Link, it should load that page which is associated with that path without reloading the page. Example:
NavLink Component:
If, we want to add some styles to the Link. So that when we click on any particular link, it can be easily identified which Link is active. For this react router provides NavLink instead of Link. Now replace Link from Navlink and add properties activeStyle. The activeStyle properties mean when we click on the Link, it should be highlighted with different style so that we can differentiate which link is currently active. Example:

- 1,112
- 14
- 14
Simply,
When you use <Link>
there isn't any active class on selected element.
In contrast, with <NavLink>
the selected element is highlighted because this element is added an active class.
Hope useful for you.

- 107
- 1
- 4
-
Some code sample will help the users. [From review](https://stackoverflow.com/review/low-quality-posts/23612520) – Vaibhav Vishal Jul 24 '19 at 10:56
Just to add in v6, NavLink
adds .active
class to the a
tag without any extra piece of code, e.g.
<NavLink to="/">Link 1</Link>
<NavLink to="/link2">Link 2</Link>
will render as:
<a href="/" className='active'>Link 1</Link>
<a href="/link2">Link 2</Link>
if the user is on the home URL (https://localhost:3000)

- 71
- 1
- 5
One difference as of v6.0.0-beta.3 is that activeClassName and activeStyle have been removed from NavLinkProps. Instead, you can pass a function to either style or className that will allow you to customize the inline styling or the class string based on the component's active state. you can also pass a function as children to customize the content of the component based on their active state, specially useful to change styles on internal elements.

- 61
- 1
- 5
The NavLink is used when you want to highlight a link as active. So, on every routing to a page, the link is highlighted according to the activeClassName . Link is for links that need no highlighting.