matchRoutes
本页内容

matchRoutes

摘要

参考文档 ↗

将给定的路由与位置匹配,并返回匹配数据。

import { matchRoutes } from "react-router";

let routes = [{
  path: "/",
  Component: Root,
  children: [{
    path: "dashboard",
    Component: Dashboard,
  }]
}];

matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]

签名

function matchRoutes<
  RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject,
>(
  routes: RouteObjectType[],
  locationArg: Partial<Location> | string,
  basename = "/",
): AgnosticRouteMatch<string, RouteObjectType>[] | null

参数

routes

要匹配的路由对象数组。

locationArg

要匹配的位置,可以是字符串路径或部分 Location 对象

basename

可选的基本路径,在匹配前从位置中剥离。默认为 /

返回

一个匹配路由的数组,如果未找到匹配项,则为 null

文档和示例 CC 4.0
编辑