我无法加载我的索引路由(主页组件),非常感谢有关我做错了什么的帮助?
我的routes.js 文件如下所示
module.exports = <Route
path="/"
getComponent={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('./Container'))
})
}}
getChildRoutes={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('./Container').childRoutes)
})
}}
getIndexRoute={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('./Container').indexRoute)
})
}}
/>
我的 Container.js 文件如下所示
export default class Container extends Component {
render = () => {
return <div>
{this.props.children}
</div>
}
}
Container.childRoutes = [
<Route
path="/:product/get-quote"
component={props => <Product productName={props.params.product} {...props} />}
/>,
<Route
path="/:product/processing-quote"
component={props => <ProcessingQuote productName={props.params.product} {...props} />}
/>
]
Container.indexRoute = <IndexRoute component={Home} />
最佳答案
如果您使用 getChildRoutes
和 getIndexRoute
处理程序,则应使用 PlainRoute
配置对象,而不是 JSX 组件。
关于javascript - 异步 IndexRoute 不加载 react 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35273829/