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
exactprop 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 href | URL | Active |
|---|---|---|
"/de" | /de | true |
"/de" | /de/p | false |
"/de/p" | /de/p | true |
"/de/p" | /de/p/123 | true |
"/de/p" | /de/p/desc/123 | true |
"/de/p/desc" | /de/p/desc/123 | true |
"/de/p/desc/123" | /de/p/desc/123 | true |
"/de/about" | /de/p/desc/123 | false |