UNPKG

@uiw-admin/layout-tabs

Version:
65 lines (64 loc) 1.62 kB
import { matchPath } from 'react-router'; /** 把数组扁平化 用于 选项卡渲染 */ export var getRoutesList = function getRoutesList(data) { if (data === void 0) { data = []; } var list = []; (function returnArr(arr) { arr.forEach(item => { if (item.children) { returnArr(item.children); } else { list.push(item); } }); })(data); return list; }; var getO = (routeListData, location) => { return routeListData.find(item => { if (location.pathname === '/' && item.index && item.redirect) { return item.index; } if (location && location.pathname && item.path && location.pathname !== '/') { return location.pathname === item.path; } return false; }); }; var getM = (routeListData, location) => { return routeListData.find(item => { if (location.pathname === '/' && item.index && item.redirect) { return item.index; } if (location && location.pathname && item.path && location.pathname !== '/') { return matchPath({ path: item.path }, location.pathname); } return false; }); }; export var getMatch = (routeListData, location) => { var o = getO(routeListData, location); if (o) { return { current: o, isMatch: false }; } else { var match = getM(routeListData, location); return { current: match, isMatch: match ? true : false }; } }; export var getMatchRender = (routeListData, location, isMatch) => { if (isMatch) { return getM(routeListData, location); } else { return getO(routeListData, location); } };