index.js 363 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;
};