Performance: Navigation links
Navigation links impact page load speed and interaction responsiveness by controlling how pages or components load and update.
import { Link } from 'react-router-dom'; function Nav() { return <Link to="/about">About</Link>; }
function Nav() { return <a href="/about">About</a>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Standard anchor <a> tag | Full DOM reload | Multiple reflows | High paint cost | [X] Bad |
| React Router <Link> component | Partial DOM update | Single reflow | Low paint cost | [OK] Good |
Link from react-router-dom in a React app?LinkLink is used to navigate between pages in a React app without refreshing the whole page.Link does not handle.react-router-dom?LinkLink component uses the to attribute to specify the path.a tags use href, but Link requires to. About uses correct syntax.Link uses to attribute [OK]import { Link } from 'react-router-dom';
function Nav() {
return (
<nav>
<Link to='/'>Home</Link>
<Link to='/profile'>Profile</Link>
</nav>
);
}<nav> element containing two <Link> components with paths '/' and '/profile'.Link behaviorLink renders as clickable links that navigate client-side without reloading the page.import { Link } from 'react-router-dom';
function Menu() {
return (
<nav>
<Link href='/dashboard'>Dashboard</Link>
</nav>
);
}LinkLink component requires the to attribute, not href.<nav> tag is properly closed, and Link can be inside nav. React import is not mandatory in React 17+ for JSX.Link needs 'to', not 'href' [OK]react-router-dom?<nav> element is the correct semantic container for navigation links, improving accessibility.Link with descriptive text and ARIA labelsLink components from react-router-dom provide client-side navigation. Adding aria-label on nav helps screen readers understand the menu purpose.div or buttons for navigation is less semantic and harms accessibility. Using a tags with href reloads pages, not client-side navigation.Pass the test and this pattern moves unknown