我的代码拆分问题是,如果模块很大,第一次用户会看到一个空白屏幕和延迟。动态路由代码拆分检查模块是否加载
function errorLoading(err) {
console.error('Dynamic page loading failed', err);
}
function loadRoute(cb) {
return (module) => cb(null, module.default); // I can't find any flag here
}
const routes = {
component: App,
childRoutes: [
{
path: '/',
getComponent(location, cb) {
System.import('pages/Home')
.then(loadRoute(cb))
.catch(errorLoading);
}
}
]
};
export default() => <Router history={browserHistory} routes={routes} />;
下面是使用动态路由代码分裂基地工作的例子。
https://github.com/ModusCreateOrg/react-dynamic-route-loading-es6/blob/master/client/pages/routes.js
我如何检查是否模块被加载与否?我必须加载一个加载指示器。
一般来说对于这一点,我的建议是不是“检查它被加载“,它是”如果它没有在X毫秒渲染,显示一个微调,这是什么适合你吗? – loganfsmyth
@loganfsmyth没有标志来检查,这是我的问题,你的建议是使用setinterval检查? –