I have an app that's based of http://moduscreate.com/code-splitting-for-react-router-with-es6-imports/ article. I've added some children routes and now my router config is as such:
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);
      }
    },
  ]
};
/index, /about and /gsgs routes trigger dynamic code loading just fine. But /gsgs/go triggers a 404 with
bundle.js:2 Dynamic page loading failed Error: Loading chunk 0 failed.(…)
What am I doing wrong? Im using
"webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta"
I have tried to reproduce the issue on the blog post and seems something is wrong. I have tried to fix that and I am not able to see that error any more.
You can refer to this commit which has changes against the current master and I am able to load child route dynamically.
Let me know if you face issues again. It would be great if you can have sample repo which can reproduce the issue, I will be glad to debug.
Happy to Help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With