React Router API Reference
    Preparing search index...

    Function matchRoutes

    • Matches the given routes to a location and returns the match data.

      Type Parameters

      • RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject

      Parameters

      • routes: RouteObjectType[]

        The array of route objects to match against.

      • locationArg: string | Partial<Location<any>>

        The location to match against, either a string path or a partial Location object

      • basename: string = "/"

        Optional base path to strip from the location before matching. Defaults to /.

      Returns null | AgnosticRouteMatch<string, RouteObjectType>[]

      An array of matched routes, or null if no matches were found.

      import { matchRoutes } from "react-router";

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

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

      @public