2
我使用与反应路由器的WebPack代码分裂和异步I做到这一点加载部件:检查出Henley Edition's article后抽象require.ensure样板从反应路由器getComponent不起作用
<Route
path="somePath"
getComponent={(next, cb) => {
require.ensure([], (require) => {
cb(null, require('../components/Example.jsx'));
});
}
}
/>
现在我尝试做这样的事情,以避免使用捆绑加载器,并仍然减少样板。
const loadLazy = (component) => {
return (next, cb) => {
require.ensure([], (require) => {
cb(null, require(component));
});
};
};
...
<Route
path="somePath"
getComponent={lazyLoad('../components/Example.jsx')}
/>
但是这在控制台抛出错误说找不到模块'../components/Example.jsx'。
为什么这不起作用?