我的代碼拆分問題是,如果模塊很大,第一次用戶會看到一個空白屏幕和延遲。動態路由代碼拆分檢查模塊是否加載
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檢查? –