我正在尝试使用Webpack 2和React Hot Loader v3实现代码拆分和热重新加载。我的问题是热重新加载只能没有代码拆分。另一个奇怪的部分是我可以热重载Structure
组件(见下文),但不是childRoutes中的组件。我一直在
[HMR] unexpected require(816) from disposed module 341
请参阅Repro here。
以下是我如何申报路线:
import { getAsyncInjectors } from './lib/asyncInjectors';
import Structure from './modules/core/components/Structure';
const errorLoading = (err) => {
console.error('Dynamic page loading failed', err);
};
const loadModule = (cb) => (componentModule) => {
cb(null, componentModule.default);
};
export default function createRootRoute(store) {
const {
injectReducer,
} = getAsyncInjectors(store);
return [{
component: Structure,
childRoutes: [{
path: '/',
getComponents(location, cb) {
const renderRoute = loadModule(cb);
Promise.all([
System.import('./modules/core/components/LaunchPage'),
System.import('./modules/core/reducers/launch'),
]).then(([component, reducer]) => {
injectReducer('launch', reducer.default);
renderRoute(component);
}).catch(errorLoading);
},
}, {
path: '/app',
getComponents(location, cb) {
const renderRoute = loadModule(cb);
Promise.all([
System.import('./modules/core/components/AppPage'),
System.import('./modules/core/reducers/app'),
]).then(([component, reducer]) => {
injectReducer('app', reducer.default);
renderRoute(component);
}).catch(errorLoading);
},
}],
}];
}
任何指针或指导都会非常感激!