PlainRoute
路由器逻辑在按如下方式实现时效果很好......
const componentRoutes = {
component : Home,
path : '/',
indexRoute : Index,
childRoutes : [
{
path: 'child',
getComponent(location, cb) {
System.import('./Child/components/child')
.then(module => cb(null, module.default))
}
}
]
}
但是当我尝试在一个单独的文件中声明时
儿童/ index.js
export default () => ({
path: 'child',
getComponent(location, cb) {
System.import('./components/child')
.then(module => cb(null, module.default))
}
})
并做:
import Child from './Child'
const componentRoutes = {
component : Home,
path : '/',
indexRoute : Index,
childRoutes : [
Child
]
}
它不再找到孩子 route
。
HashHistory用作路由器的历史记录。项目结构如下:
答案 0 :(得分:3)
在导出功能的Child/index.js
中,然后将该功能传递给childRoutes
。你真正想要的是从该函数返回的对象。只需调用函数Child()
:
childRoutes : [
Child()
]
或者您可以直接导出对象,而不将其包装在Child/index.js
:
export default {
path: 'child',
getComponent(location, cb) {
System.import('./components/child')
.then(module => cb(null, module.default))
}
}