1

我正在尝试使用 Webpack 2 和 React Hot Loader v3 实现代码拆分和热重载。我的问题是热重载只能在没有代码拆分的情况下工作。另一个奇怪的部分是我可以热重载Structure组件(见下文),但不能在 childRoutes 中重新加载组件。我不断得到

[HMR] unexpected require(816) from disposed module 341

请参阅此处的复制。


以下是我声明路线的方式:

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);
      },
    }],
  }];
}

任何指示或指导将不胜感激!

4

0 回答 0