我有一个root route
定义:
const rootRoute = {
childRoutes: [{
path: '/',
component: require('./screens/Container'),
appGlobalVars: appGlobalVars,
childRoutes: [
require('./routes/ListApps'),
require('./routes/Settings'),
require('./routes/Profile')
]
}]
};
var runApp = (appGlobalVars) => {
var routes = (
<Provider store={store}>
<Router history={ history } routes={rootRoute} />
</Provider>
);
render(routes, document.getElementById('app'));
};
以及一些带有嵌套动态路由的设置:
./routes/Settings/index.js:
module.exports = {
path: 'settings',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('../../screens/AppSettings'))
})
},
getChildRoutes(partialNextState, cb) {
require.ensure([], (require) => {
cb(null, [
require('./General'),
require('./Users')
])
})
},
};
/settings
是父组件,它渲染{this.props.children}
反应路由器传递。例如,如果我导航到/settings/general
我将settings
渲染,它又将渲染general
为它的孩子:
./routes/Settings/General.js
module.exports = {
path: 'general',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('../../screens/AppSettings/General'))
})
}
};
这没关系,但我想做的是定义默认子组件Settings
在导航到/settings
.
简而言之:有没有办法IndexRoute
在使用动态路由时定义类似的东西?