Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to mix JSX and regular object for routes in React Router?

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 = settingsRoutes
var settingsRoutes = require('settingsRoutes')

<Route path='/' component={ Container }>
  <Route path='register' component={ Register } />
  <Route path='signin' component={ Signin } />
  <Route path='signout' component={ Signout } } />
  { settingsRoutes }
</Route>
like image 857
Evan Hobbs Avatar asked Oct 28 '25 08:10

Evan Hobbs


1 Answers

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>
like image 124
taion Avatar answered Oct 31 '25 00:10

taion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!