Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function matchRoutes(
_routes,
currentURL = "/",
parentPath = "/",
redirect = false
) {
const routes = isArray(_routes) ? flatten(_routes) : toArray(_routes);
const [pathToMatch = "/", search = ""] = currentURL.split("?");
const params = mapSearchParams(search);
routes.sort(pathRankSort);
for (let i = 0, len = routes.length; i < len; i++) {
const route = routes[i];
const props = route.props || emptyObject;
const routePath = props.from || props.path || "/";
const location =
parentPath + toPartialURL(routePath, parentPath).replace(/\/\//g, "/");
const isLast = isEmpty(props.children);
const matchBase = matchPath(isLast, location, pathToMatch);
if (matchBase) {
let children = props.children;
export default function match(routes, currentURL: any) {
const location: string = getURLString(currentURL);
return matchRoutes(toArray(routes), encodeURI(location), "/");
}