index.js 610 Bytes
Newer Older
duanledexianxianxian's avatar
init  
duanledexianxianxian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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;
};
duanledexianxianxian's avatar
sync  
duanledexianxianxian committed
18 19 20 21 22 23 24 25 26 27 28


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;
};