dva icon indicating copy to clipboard operation
dva copied to clipboard

动态路由代码切割问

Open iceshu opened this issue 9 years ago • 6 comments

<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

iceshu avatar Apr 14 '17 03:04 iceshu

我这边是把 route 使用 json 配置的方式写到 各组件目录的,我打包出来的就是分开的

zjxpcyc avatar Apr 28 '17 01:04 zjxpcyc

@zjxpcyc 可以借鉴一下你的配置吗?多谢

nil-w avatar May 09 '17 08:05 nil-w

@zjxpcyc 同求

sbyps avatar May 10 '17 07:05 sbyps

@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}/>;

}

我这样配了还是不能拆

iceshu avatar May 24 '17 03:05 iceshu

这个就是能力之外了,目前我理解的应该是可以的。另外官方的例子 huge-apps 很简单,就可以拆。(官方例子是 v3 的)

zjxpcyc avatar May 25 '17 00:05 zjxpcyc