Webpack 2 + React - 使用System.import进行代码拆分时的嵌套路由

nuw*_*way 9 javascript reactjs webpack react-router webpack-dev-server

我有一个基于http://moduscreate.com/code-splitting-for-react-router-with-es6-imports/文章的应用程序.我添加了一些子路由,现在我的路由器配置是这样的:

function errorLoading(err) {
  console.error('Dynamic page loading failed', err);
}

function loadRoute(cb) {
  console.log('load route called');
  return (module) => cb(null, module.default);
}

const obj = {
  component: App,
  childRoutes: [
    {
      path: '/',
      getComponent(location, cb) {
        System.import('pages/Home')
          .then(loadRoute(cb))
          .catch(errorLoading);
      }
    },
    {
      path: '/gsgs',
      getComponent(location, cb) {
        System.import('pages/Gsgs')
          .then(loadRoute(cb))
          .catch(errorLoading);
      },
      childRoutes: [
        {
          path: 'go',
          getComponent(location, cb) {
            System.import('pages/Gsgs/Home.js')
              .then(loadRoute(cb))
              .catch(errorLoading);
          },
        }
      ]
    },
    {
      path: '/about',
      getComponent(location, cb) {
        System.import('pages/About')
          .then(loadRoute(cb))
          .catch(errorLoading);
      }
    },
  ]
};
Run Code Online (Sandbox Code Playgroud)

/ index,/ about和/ gsgs routes触发动态代码加载就好了.但/ gsgs/go会触发404

bundle.js:2动态页面加载失败错误:加载块0失败.(...)

我究竟做错了什么?我正在使用

"webpack": "^2.1.0-beta.4",
"webpack-dev-server": "^2.0.0-beta"
Run Code Online (Sandbox Code Playgroud)

小智 2

我尝试在博客文章中重现该问题,但似乎有些问题。我已尝试修复该问题,但无法再看到该错误。

您可以参考此提交,该提交对当前主路由进行了更改,并且我能够动态加载子路由。

如果您再次遇到问题,请告诉我。如果您能提供可以重现该问题的示例存储库,那就太好了,我很乐意进行调试。

很高兴能帮助你。