@uiw-admin/layout-tabs
Version:
71 lines (70 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRoutesList = exports.getMatchRender = exports.getMatch = void 0;
var _reactRouter = require("react-router");
/** 把数组扁平化 用于 选项卡渲染 */
var getRoutesList = function getRoutesList() {
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var list = [];
(function returnArr(arr) {
arr.forEach(function (item) {
if (item.children) {
returnArr(item.children);
} else {
list.push(item);
}
});
})(data);
return list;
};
exports.getRoutesList = getRoutesList;
var getO = function getO(routeListData, location) {
return routeListData.find(function (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 = function getM(routeListData, location) {
return routeListData.find(function (item) {
if (location.pathname === '/' && item.index && item.redirect) {
return item.index;
}
if (location && location.pathname && item.path && location.pathname !== '/') {
return (0, _reactRouter.matchPath)({
path: item.path
}, location.pathname);
}
return false;
});
};
var getMatch = function 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
};
}
};
exports.getMatch = getMatch;
var getMatchRender = function getMatchRender(routeListData, location, isMatch) {
if (isMatch) {
return getM(routeListData, location);
} else {
return getO(routeListData, location);
}
};
exports.getMatchRender = getMatchRender;