Swirski UI

Hook

useIsPathnameActive

Checks whether a pathname matches the current URL path, including nested routes.

Import

import { useIsPathnameActive } from "@swirski/ui";

Preview

Live render

useIsPathnameActive

Preview
Active route helper

Usage

const active = useIsPathnameActive(
  "/components",
  "/components/button",
);

Props

3 documented
PropTypeDefaultNotes
pathnameRequiredstring | URL-Target pathname or URL to match.
currentUrlRequiredstring | URL-Current route URL or pathname.
options.exactbooleanfalseRequire an exact pathname match.

Returns

1 documented
ValueTypeNotes
activebooleanTrue when currentUrl matches pathname or a nested child path.
Previous: useEscapeKeyNext: useLocalStorage