【发布时间】:2016-02-11 04:12:29
【问题描述】:
我有一个路由组件,我想用 webpack 异步加载它:
<Route path="dashboard" getComponent={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('./Containers/Dashboard'));
});
}}>
如果您有很多其他需要异步块加载的路由,那么这是很多样板文件。所以我想,让我们把它重构为一个辅助方法:
const loadContainerAsync = route => (location, cb) => {
require.ensure([], (require) => {
cb(null, require('../Containers/' + route));
});
};
// much 'nicer syntax'
<Route path="dashboard" getComponent={loadContainerAsync('Dashboard')} />
显然,当我查看 firefox-devtools 中的网络选项卡时,loadContainerAsync 函数的行为无法正常运行。知道我的函数 loadContainerAsync 有什么问题吗?
【问题讨论】:
标签: webpack react-router