Back to React Router

useMatch

docs/api/hooks/useMatch.md

7.6.21.2 KB
Original Source

useMatch

<!-- ⚠️ ⚠️ IMPORTANT ⚠️ ⚠️ Thank you for helping improve our documentation! This file is auto-generated from the JSDoc comments in the source code, so please edit the JSDoc comments in the file below and this file will be re-generated once those changes are merged. https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/hooks.tsx -->

[MODES: framework, data, declarative]

Summary

Reference Documentation ↗

Returns a PathMatch object if the given pattern matches the current URL. This is useful for components that need to know "active" state, e.g. <NavLink>.

Signature

tsx
function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(
  pattern: PathPattern<Path> | Path,
): PathMatch<ParamKey> | null

Params

pattern

The pattern to match against the current Location

Returns

The path match object if the pattern matches, null otherwise