Created
August 1, 2023 17:07
-
-
Save lamualfa/f0f4a28c4f4f8f4cbfa1e6361b3ba8a3 to your computer and use it in GitHub Desktop.
Hook to check is path active or no in React Router v6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LinkProps, useMatch, useResolvedPath } from 'react-router-dom' | |
export function useIsActivePath(path: LinkProps['to'], strict = true) { | |
const resolvedPath = useResolvedPath(path) | |
const match = useMatch({ path: resolvedPath.pathname, end: strict }) | |
return match !== null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment