Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Active links with NavLink in React Router

NavLink is a Link that knows whether it points to the current location, so menus and tabs can highlight the page you are on.

All React Router examples React Router: usage and stats

Active links with NavLink in React Router: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Use NavLink for menus. The tab bar renders NavLink instead of Link, because each tab needs to look different when it is the current page. [1]
  2. Style the .active class. A small stylesheet created in code targets .tabs a.active. Home and Inbox get the purple pill only through that class. [1]
  3. Use the isActive callbacks. The Drafts tab passes a function as children to swap ○ for ●, and the Settings tab passes a function to style that turns the text amber when isActive is true. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

Checked Oct 12, 2026: it starts without errors in Chromium with react-router-dom 7.18.4, react 19.3.0, react-dom 19.3.0. Needs WebGL.

More React Router examples

Basic routing in React Router Nested routes with Outlet in React Router URL params with useParams in React Router Programmatic navigation with useNavigate

Sources

  1. Docs: start › declarative › navigating

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with React Router? Ask AgentGid →