Tôi có một ứng dụng dựa trên bài viết http://moduscreate.com/code-splitting-for-react-router-with-es6-imports/. Tôi đã thêm một số tuyến đường dành cho trẻ em và giờ đây cấu hình bộ định tuyến của tôi là như vậy:Webpack 2 + React - các tuyến lồng nhau khi chia tách mã với System.import
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// gsgs routes kích hoạt tải mã động chỉ tốt. Nhưng/gsgs/go kích hoạt 404 với
bundle.js:2 Dynamic page loading failed Error: Loading chunk 0 failed.(…)
Tôi đang làm gì sai? Im sử dụng
"webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta"
không chắc chắn lý do bạn nhận được lỗi nhưng chỉ cần lưu ý rằng bạn có thể sử dụng phần tử JSX để thiết lập tuyến đường thay vì một đối tượng lớn không đáng kể. –
Yea Tôi biết về phần tử jsx cho bộ định tuyến, tôi tìm thấy chú thích đối tượng rõ ràng hơn và dễ đọc hơn – nuway