React路由器Webpack 2代码拆分-使用getChildRoutes()
当我导航到React路由器Webpack 2代码拆分-使用getChildRoutes(),webpack,react-router,webpack-2,code-splitting,Webpack,React Router,Webpack 2,Code Splitting,当我导航到/home时,我有一个显示主页图标、关于、设置等的导航栏。显示此导航栏的组件位于HomeContainer中。根据url,我想加载HomeContainer的路由。我用的是wepback 2,代码拆分,react路由器3 这是我的文件 import React from 'react'; import { Router, hashHistory } from 'react-router'; import App from './components/App'; import Porta
/home
时,我有一个显示主页图标、关于、设置等的导航栏。显示此导航栏的组件位于HomeContainer
中。根据url,我想加载HomeContainer
的路由。我用的是wepback 2,代码拆分,react路由器3
这是我的文件
import React from 'react';
import { Router, hashHistory } from 'react-router';
import App from './components/App';
import Portal from './components/portal/Portal';
const componentRoutes = {
component: App,
path: '/',
indexRoute: { component: Portal },
childRoutes: [
{
path: 'login',
getComponent(location, cb) {
System.import('./components/login/Login')
.then(module => cb(null, module.default));
}
},
{
path: 'home',
getComponent(location, cb) {
System.import('./components/homepage/HomeContainer')
.then(module => cb(null, module.default));
},
getIndexRoute(partialNextState, callback) {
require.ensure([], function (require) {
callback(null, {
component: require('./components/homepage/Home'),
})
})
},
getChildRoutes(partialNextState, callback) {
require.ensure([], function (require) {
callback(null, [
require('./components/homepage/About').default
])
})
}
}
]
};
const Routes = () => {
return <Router history={hashHistory} routes={componentRoutes} />
};
export default Routes;
从“React”导入React;
从“react Router”导入{Router,hashHistory};
从“./components/App”导入应用程序;
从“./components/Portal/Portal”导入门户;
常量组件路由={
组件:应用程序,
路径:“/”,
indexRoute:{组件:门户},
儿童路线:[
{
路径:“登录”,
getComponent(位置,cb){
System.import(“./components/login/login”)
.then(module=>cb(null,module.default));
}
},
{
路径:“家”,
getComponent(位置,cb){
System.import(“./components/homepage/HomeContainer”)
.then(module=>cb(null,module.default));
},
getIndexRoute(partialNextState,回调){
要求。确保([],功能(要求){
回调(null{
组件:需要('./组件/主页/主页'),
})
})
},
getChildRoutes(partialNextState,回调){
要求。确保([],功能(要求){
回调(null[
要求('./组件/主页/关于')。默认值
])
})
}
}
]
};
常数路由=()=>{
返回
};
导出默认路径;
问题是,如何获得要渲染的
about
组件?我想能够导航到<代码> /home //<代码>,让它加载,作为子代码的< <代码> HealEngor < /C> >。
getChildRoutes(partialNextState, callback) {
require.ensure([], function (require) {
callback(null, [{
path: 'about',
component: require('./components/homepage/About').default
}
])
})
}]