一般的路由配置,路径path和组件component总是一一对应的,如:
const routes = {
path: '/',
component: App,
indexRoute: { component: Dashboard },
childRoutes: [
{ path: 'about', component: About },
{
path: 'inbox',
component: Inbox,
childRoutes: [{
path: 'messages/:id',
onEnter: ({ params }, replace) => replace(`/messages/${params.id}`)
}]
},
{
component: Inbox,
childRoutes: [{
path: 'messages/:id', component: Message
}]
}
]
}
但动态路由的配置就看不懂了,子路由路径到底配置在哪儿?
const CourseRoute = {
path: 'course/:courseId',
getChildRoutes(partialNextState, callback) {
require.ensure([], function (require) {
callback(null, [
require('./routes/Announcements'),
require('./routes/Assignments'),
require('./routes/Grades'),
])
})
},
getIndexRoute(partialNextState, callback) {
require.ensure([], function (require) {
callback(null, {
component: require('./components/Index'),
})
})
},
getComponents(nextState, callback) {
require.ensure([], function (require) {
callback(null, require('./components/Course'))
})
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
ok,我大致了解了。这是另外一种写法,不是所有路由配置放到一个文件,而是各个模块都有各自的路由配置文件。
ref:http://stackoverflow.com/questions/39420032/how-to-define-a-react-routers-indexroute-when-using-dynamic-routing