Home route · exact match
Home
The Home menu link uses exact matching. It is active only when the current route is the home route—not when you visit About.
Route shown in this static demo
#/
React Router concept · Custom Link
This is a static-site adaptation of the React Router v5 example. The active menu item gets a special style and a “>” marker. Hash-based routes keep the demo working on static hosting.
Home route · exact match
The Home menu link uses exact matching. It is active only when the current route is the home route—not when you visit About.
Route shown in this static demo
#/
About route · prefix match
The About menu link matches this route and nested routes such as #/about/team. Try the nested route to see About remain active.
No matching page
This small example only defines Home and About routes.
Return homeOriginal React Router idea
In React Router v5, useRouteMatch checks the current route. When it matches, the component adds an active class and prints the marker before a normal Link.
function OldSchoolMenuLink({ label, to, activeOnlyWhenExact }) {
const match = useRouteMatch({
path: to,
exact: activeOnlyWhenExact
});
return (
<div className={match ? "active" : ""}>
{match && "> "}
<Link to={to}>{label}</Link>
</div>
);
}
Static demo note: the original snippet uses React Router v5 and BrowserRouter. This page mirrors its matching and active-state behavior with HTML, CSS, and hash navigation; it does not run React.
React Router v5 reference
In the original React example, useRouteMatch checks the current route. Home requests an exact match, while About also matches nested routes.
function OldSchoolMenuLink({ label, to, activeOnlyWhenExact }) {
const match = useRouteMatch({
path: to,
exact: activeOnlyWhenExact
});
return (
<div className={match ? "active" : ""}>
{match && "> "}
<Link to={to}>{label}</Link>
</div>
);
}
This page is a static HTML adaptation. Its interactive example uses hash navigation so it works on static hosting; the code above is the React Router v5 pattern and needs a React application to run.