V Knowledgebase

React Router concept · Custom Link

Make the active link stand out.

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.

About saving: this page can open the original example, but it cannot save content directly there. Direct storage would require the external service to provide an authenticated, documented API or an authorized integration. No data is sent automatically.

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

#/

Original React Router idea

How the custom link decides it is active

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

How the original custom link works

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.