Link renders as an actual <a> element in the DOM, preserving standard accessibility and behaviors like middle-click-to-open-in-new-tab, but intercepts a regular left-click to perform client-side navigation via the History API instead of letting the browser's default full-page navigation happen. The to prop specifies the destination path, accepting either a plain string or an object with pathname/search/hash for more structured URLs, and NavLink, a specialized variant, additionally applies a distinguishing style or class automatically when its target path matches the current URL, commonly used for highlighting the active item in a navigation menu.
1Understanding Link
Link renders as an actual <a> element in the DOM, preserving standard accessibility and behaviors like middle-click-to-open-in-new-tab, but intercepts a regular left-click to perform client-side navigation via the History API instead of letting the browser's default full-page navigation happen. The to prop specifies the destination path, accepting either a plain string or an object with pathname/search/hash for more structured URLs, and NavLink, a specialized variant, additionally applies a distinguishing style or class automatically when its target path matches the current URL, commonly used for highlighting the active item in a navigation menu.
Use NavLink instead of Link specifically when you need to automatically style the currently active navigation item — it handles that active-state comparison for you, rather than you needing to compare the current path against each link's target manually.
import { Link } from 'react-router-dom';
function Nav() {
return (
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
);
}2Practical Example
Here is a real-world application of Link showing how it is used in production React code.
import { NavLink } from 'react-router-dom';
function Nav() {
return (
<NavLink to="/about" className={({ isActive }) => isActive ? 'active-link' : ''}>
About
</NavLink>
);
}
// When the current URL is /about:3Best Practices
Follow these guidelines when working with Link:
1. Use Link, or NavLink, instead of a plain <a> tag for any internal navigation, so it stays client-side and doesn't trigger a full page reload
2. Use NavLink over plain Link specifically when a navigation item needs to visually indicate it's the currently active route
3. Reserve plain <a> tags for genuinely external links, or resource links like a PDF download, where full-page browser navigation is actually the intended, correct behavior
Tip: Use NavLink instead of Link specifically when you need to automatically style the currently active navigation item — it handles that active-state comparison for you, rather than you needing to compare the current path against each link's target manually.
import { Link } from 'react-router-dom';
function Nav() {
return (
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
);
}