Routes使用对象配置时,一直无效?
Closed this issue · 4 comments
git-lt commented
const rootRoute = {
path: '/',
component: App,
indexRoute: { component: Home },
childRoutes: [
{ path: 'home', component: Home },
{
path: 'news',
getComponent(nextState, callback) {
//如果是服务端,直接返回
if(__SERVER__){
callback(null, require('./containers/News'))
}else{
// client端,利用webpack的 Code Splitting 功能,分片打包实现懒加载
require.ensure([], function (require) {
callback(null, require('./containers/News'))
})
}
}
},
{
path: 'about',
getComponent(nextState, callback) {
if(__SERVER__){
callback(null, require('./containers/About'))
}else{
require.ensure([], function (require) {
callback(null, require('./containers/About'))
})
}
}
}
]
}
export default ( <Router history={browserHistory} routes={rootRoute} /> )
访问的时候,页面上一直显示404,好像路由没有起作用,但是如果使用jsx的方式,又是可以的,可能帮忙看一下吗?
wssgcg1213 commented
服务端路由暂时不支持 require.ensure
,在dev模式下服务端没有经过webpack打包,所以不支持此语法
git-lt commented
那服务端打包是否也可以使用webpack打包?
wssgcg1213 commented
可以的,只是目前还不支持,你可以根据需求自行修改一下打包配置
require.ensure 不是标准,是webpack单独提供的功能,所以尽量还是不要太依赖这种写法比较好
git-lt commented
好的,谢谢