export const meunsTreeSelect = (data: any) => {
const item: any = [];
data.forEach((list: any) => {
const newData = {};
const meta = {};
meta.title =
list.name;
newData.meta = meta;
newData.path = list.path;
newData.element = lazyLoad(list.component);
newData.children = list.children ? meunsTreeSelect(list.children) : null; // 如果还有子集,就再次调用自己
item.push(newData);
});
return item;
};
const lazyLoad = (moduleName: string) => {
let Module;
if (moduleName === 'layouts') {
Module = lazy(() => import(`@/${moduleName}/index.tsx`));
} else {
Module = lazy(() => import(`@/pages/${moduleName}.tsx`));
}
return (
<Suspense fallback={<>加载中...</>}>
<Module />
</Suspense>
);
};
点击菜单后,报错
Uncaught TypeError: Cannot read properties of undefined (reading '0')