Skip to main content

useIsLinkActive

declare function useParams(linkHref: string, exact = false, isActive?: (currentPathname: string, linkPathname: string) => boolean): Readonly<T>;

The useIsLinkActive hook compares complete final linkHref constructed for <RouterNavLink (or any other passed) with the current pathname to make a decision if the passed linkHref is active or not.

By default, it checks for:

  • full match;
  • checks for a full match ONLY when exact prop is passed;
  • bails out with false when linkHref points to root ('/' or '/{language}') but current URL is different;
  • compares if linkHref starts with the same complete segments as current pathname.

You can provide your own comparison logic via isActive prop.

Comparison logic with exact prop => FULL MATCH ONLY.

Default comparison logic:

Link hrefURLActive
"/de"/detrue
"/de"/de/pfalse
"/de/p"/de/ptrue
"/de/p"/de/p/123true
"/de/p"/de/p/desc/123true
"/de/p/desc"/de/p/desc/123true
"/de/p/desc/123"/de/p/desc/123true
"/de/about"/de/p/desc/123false