With React Router, I see here that I can define my routes as either JSX or just a normal object. I have a use case where I would like to share settingsRoutes with another part of my application as a normal object but still use JSX for the other routes. The second code block is what I was like to do. Is this mixing of JSX and objects possible with react router??
const settingsRoutes = [{
  path: 'settings',
  component: Settings,
  childRoutes: [
    {
      path: 'info',
      component: SettingsInfo
    }
  ]
}]
module.exports = settingsRoutesvar settingsRoutes = require('settingsRoutes')
<Route path='/' component={ Container }>
  <Route path='register' component={ Register } />
  <Route path='signin' component={ Signin } />
  <Route path='signout' component={ Signout } } />
  { settingsRoutes }
</Route>Do this:
<Route path='/' component={ Container }>
  <Route path='register' component={ Register } />
  <Route path='signin' component={ Signin } />
  <Route path='signout' component={ Signout } } />
  <Route childRoutes={settingsRoutes} />
</Route>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With