可以实现与阵营路由器! :)
但我建议你检查出来的“普通路由”的方式来配置你的路线:
https://github.com/reactjs/react-router/blob/master/docs/guides/RouteConfiguration.md#configuration-with-plain-routes
利用这一点,你就会开始一个routes
对象的工作,你可以只需require
其他路线并根据这些组合创建您的路线。类似的东西:
const routes = {
path: '/',
component: App,
childRoutes: [
require('./profile'),
require('./explore')
]
}
然后在你profile.js
(你可以在同一做到explore.js
)文件,你将有类似的东西:
/* Import the ProfileDashboard and ProfileRepos here */
const profileRoutes = {
path: 'profile',
childRoutes: [{
path: 'dashboard',
component: ProfileDashboard
}, {
path: 'repos',
component: ProfileRepos
}]
};
而且这种方式可以实现你想要的。
如果你真的不能使用普通的路线,你可以做这样的事情:
<Route path="/" component={App}>
{ require('./profile') }
{ require('./explore') }
</Route>
而你profile.js
,例如:
module.exports = (
<Route path="profile">
<Route path="dashboard" component={ProfileDashboard} />
<Route path="dashboard" component={ProfileRepos} />
</Route>
);
我不知道是什么阵营路由器版本,但您可以在任何版本中实现该版本,但作为建议,请尝试使用最新的版本。因为它处理很多很酷的东西。
希望它有帮助!
我的问题是你为什么要这么做? –