Part 15 / Topic 4 of 9
NavLink, and what end actually controls
NavLink is Link plus one extra thing: it already knows whether its own to matches the current URL, and hands that back as isActive - so a nav bar can highlight the current tab without the app separately tracking "which page is this." By default, that match is not exact-only: a NavLink also counts as active on any path nested under its own, which is usually exactly what you want - a "Bookings" tab staying lit up while looking at one specific booking. examples/04_navlink_active_state.jsx's NavBarDefault:
// examples/04_navlink_active_state.jsx
<NavLink to="/bookings" className={({ isActive }) => (isActive ? "active" : "")}>
Bookings
</NavLink>
At /bookings, this really carries an "active" class - and it really stays "active" after clicking through to /bookings/4471, a nested detail page, with no extra code (examples/04_navlink_active_state.test.jsx). end is the opt-out of that: NavBarWithEnd's identical link, with end added, requires an exact match only - it really switches off the instant the URL moves to /bookings/4471, even though /bookings is still a prefix of it. Reach for end specifically when a tab should represent "exactly this page," not "this page or anything under it."
⚠️ Verified against the installed
[email protected]source, not assumed from an older version's behavior or a tutorial: aNavLink to="/"is a special case and is already exact-match-only, with or withoutend- its own match check requires the character right after the matched text to be/, which for a one-character target ("/"itself) can only happen on a path starting with//, something no real route in this course ever produces. If you've read that a rootNavLink"lights up on every page withoutend," that described an older release; it does not reproduce on the version this part installed (examples/04_navlink_active_state.test.jsx's third test proves it directly). A plain<Link>(the same file's "Jump to booking #4471") never needed any of this - it is not a tab, so it never hadisActivein the first place.
Done here? The practice set for Part 15 — including the solutions — is on the part page.