useMatch

Summary

Reference Documentation ↗

指定されたパターンが現在のURLと一致する場合、PathMatch オブジェクトを返します。これは、コンポーネントが「アクティブ」状態を知る必要がある場合に便利です。例えば、<NavLink> などです。

Signature

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

Params

pattern

現在の Location と照合するパターン。

Returns

パターンが一致した場合、パス一致オブジェクトを返します。それ以外の場合は null を返します。