Async IndexRoute 不加载 react-router
Async IndexRoute doesn't load with react-router
我无法加载我的索引路由(Home 组件),非常感谢您提供有关我做错了什么的帮助?
我的 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 组件。
我无法加载我的索引路由(Home 组件),非常感谢您提供有关我做错了什么的帮助?
我的 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 组件。