Replies: 1 comment
-
umi 3 不维护了,建议升级到 umi 4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
config.js里已开启dynamicImport
路由不是一个个页面配置的,而是根据路径把pages目录下的文件自动生成路由,这种方式该怎么实现懒加载呀?尝试半天都不成功,有没有大佬遇到过呢?
const findComponents = (files: __WebpackModuleApi.RequireContext) => {
const modules = {};
files.keys().forEach((key) => {
// 删除路径开头的./ 以及结尾的 /index;
const str = key.replace(/(./|.tsx)/g, '').replace('/index', '');
// modules[str] = files(key).default;
modules[str] = dynamic({
loader: async function () {
const { default: Comp } = await import(
/* webpackChunkName: "oprecord" */
../../pages/${str}/
);
return Comp;
},
});
// modules[str] =React.createElement(require(
../../pages/${str}/
).default)// modules[str] =require(
../../pages/${str}/
).default});
return modules;
};
Beta Was this translation helpful? Give feedback.
All reactions