Code splitting not working(based on react router's dynamic routes)
See original GitHub issueHi! I’m trying to implement code splitting based on router’s dynamic feature(https://github.com/rackt/react-router/blob/master/docs/guides/advanced/DynamicRouting.md) like that
path: 'course/:courseId',
getChildRoutes(location, callback) {
require.ensure([], function (require) {
callback(null, [
require('./routes/Announcements'),
require('./routes/Assignments'),
require('./routes/Grades'),
])
})
},
getIndexRoute(location, callback) {
require.ensure([], function (require) {
callback(null, {
component: require('./components/Index'),
})
})
},
getComponents(location, callback) {
require.ensure([], function (require) {
callback(null, require('./components/Course'))
})
}
It works fine in this commit(just react-router and basic server render). https://github.com/EcutDavid/example-react-router-server-rendering-lazy-routes/commit/6e070ee4a573fefe730dec2eadbe6dc38d0e5529
But it not works on my application based on this project.
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
RoutingContext.
Currently my code like that: -routes –index.js
// polyfill webpack require.ensure
if (typeof require.ensure !== 'function') require.ensure = (d, c) => c(require)
export default {
component: 'div',
getChildRoutes(location, cb) {
require.ensure([], (require) => {
cb(null, [
require('./ShareGraphRoute'),
require('./AppRoute'),
require('./NotFoundRoute'),
])
})
}
}
-routes –ShareGraphRoute
// polyfill webpack require.ensure
if (typeof require.ensure !== 'function') require.ensure = (d, c) => c(require)
import {
SHARE_GRAPH_PATH,
} from 'constants/defaults'
export default {
path: SHARE_GRAPH_PATH,
getComponent(location, cb) {
require.ensure([], (require) => {
cb(null, require('components/ShareGraph'))
})
},
}
Seems need change in server.js
or I made some mistakes, any hint?
thanks!!
Issue Analytics
- State:
- Created 8 years ago
- Comments:14
You are welcome 😃
@EcutDavid have you got polifyll in your first file? What babel are you using? If you are using babel6, you need to specify
default
to use default export in require like this:is your source hosted somewhere? I can look and help you 😃