#
useRouteMatch
Execute React Router's matching algorithm against the registered routes and a given location to determine if any route match the location.
#
Reference
const match = useRouteMatch(locationArg)
#
Parameters
locationArg: The location to match the route paths against.options: An optional object literal of options:throwWhenThereIsNoMatch: Whether or not to throw anErrorif no route matchlocationArg.
#
Returns
A Route object if there's a matching route, otherwise if throwWhenThereIsNoMatch is enabled and no route match the given location, an Error is thrown.
If throwWhenThereIsNoMatch is disabled and there's no route matching locationArg, undefined is returned.
#
Usage
#
Using useLocation
import { useLocation } from "react-router-dom";
import { useRouteMatch } from "@squide/firefly";
const location = useLocation();
const activeRoute = useRouteMatch(location);
#
Using window.location
import { useRouteMatch } from "@squide/firefly";
const activeRoute = useRouteMatch(window.location);