import pathRegexp from "path-to-regexp"; /** * props.route.routes * @param router [{}] * @param pathname string */ export const getActiveMenu = (menus = [], pathname) => { for(let i=0;i<menus.length;i++){ const menu=menus[i] if(menu.path && pathRegexp(`${menu.path}/(.*)`).test(`${pathname}/`)){ return menu } } return undefined; };
export const getActiveRoute = (routes = [], pathname) => { for(let i=0;i<routes.length;i++){ const route=routes[i] if(route.path && pathRegexp(`${route.path}`).test(`${pathname}/`)){ return route } } return undefined; };