matchPath
declare function matchPath<
ParamKey extends string = string
>(
pattern: PathPattern | string,
pathname: string
): PathMatch<ParamKey> | null;
interface PathMatch<ParamKey extends string = string> {
params: Params<ParamKey>;
pathname: string;
pattern: PathPattern;
}
interface PathPattern {
path: string;
caseSensitive?: boolean;
end?: boolean;
}
matchPath
比對路由路徑形式與 URL 路徑名稱並且傳回比對資訊。當你需要手動執行路由匹配演算法來判定路由路徑是否匹配時,這將會很有用。如果形式與給定的路徑名稱不符,將傳回 null
。
useMatch
Hook 內部使用這個函式來根據目前位置比對路由路徑。