动态路由代码切割问
<Router history={history}>
<Route path="/" component={App}>
<IndexRedirect to='home'/>
<Route path="home" component={App}>
<IndexRedirect to='index'/>
<Route path="index" getComponent={(location, callback) => {
registerModel(app, require('./models/home/home'));
require.ensure([], function (require) {
callback(null, require('./routes/home/pages/home'));
}, 'home');
}}
/>
<Route path="zxlists" getComponent={(location, callback) => {
registerModel(app, require('./models/home/home'));
require.ensure([], function (require) {
callback(null, require('./routes/home/pages/zxlists'));
});
}}/>
</Route>
</Route>
</Router>
路由我这样配置的 打包的话 还是打成了一个包 demo我看了 必须要按照那样写才能分开打包么 @sorrycc
我这边是把 route 使用 json 配置的方式写到 各组件目录的,我打包出来的就是分开的
@zjxpcyc 可以借鉴一下你的配置吗?多谢
@zjxpcyc 同求
@yqwoe @sbyps 就是按照官方说明的配置,没有特殊性 https://github.com/ReactTraining/react-router/blob/v2.8.1/docs/guides/DynamicRouting.md 另外,route 各组件的配置参照 https://github.com/ReactTraining/react-router/blob/v2.8.1/docs/guides/RouteConfiguration.md#configuration-with-plain-routes
@zjpcyc
function RouterConfig({history, app}) {
const rootRoute = [
{
path: '/',
name: 'home',
indexRoute: {onEnter: (nextState, replace) => replace('home')},
getComponents(location, cb){
require.ensure(['./routes/IndexPage'], (require)=> {
cb(null, require('./routes/IndexPage'))
})
}
},
{
path: '/home',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('./routes/IndexPage'))
}, 'home')
}
}, {
path: '/activites',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('./routes/home/activities'))
}, 'activites')
}
}, {
path: '/login',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('./routes/home/login'))
}, 'login')
}
}
];
return <Router history={history} routes={rootRoute}/>;
}
我这样配了还是不能拆
这个就是能力之外了,目前我理解的应该是可以的。另外官方的例子 huge-apps 很简单,就可以拆。(官方例子是 v3 的)