简体   繁体   中英

Async IndexRoute doesn't load with react-router

I can't get my index route (Home component) to load, would really appreciate some help as to what I'm doing wrong?

My routes.js file looks like this

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)
      })
    }}
/>

and my Container.js file looks like this

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} />

如果使用的是getChildRoutesgetIndexRoute处理程序,则应使用PlainRoute配置对象,而不是JSX组件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM