Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Using react-router childRoutes

I have a SPA which has 2 tabs in which data is rendered. The component and corresponding URL structure is as follows:

URL --> Component

/ --> PostContainer  
/create --> MessageFormContainer  
/update/:id --> MessageUpdatesContainer
/update/:id/infoCreate --> InfoCreateContainer  
/update/:id/infoView/:id --> InfoViewContainer

If I define the routes with each having its own specific URL (sample 1), then the router works; but if use childRoutes to nest the components (sample 2), the the formed URL is displayed the URL bar, but nothing is rendered on the screen.

Sample 1:

const AppRoutes = {
  path: '/',
  component: MainContainer,
  indexRoute: { component: PostsContainer },
  childRoutes: [{
    path: 'create',
    component: MessageFormContainer
  },{
    path: 'update/:id',
    component: MessageUpdatesContainer,
  },{
    path: 'update/:id/infoCreate',
    component: InfoCreateContainer
  },{
      path: 'update/:id/infoView/:id',
      component: InfoViewContainer
  }]
}

Works.

Sample 2:

const routes = {
  path: '/',
  component: MainContainer,
  indexRoute: { component: PostsContainer },
  childRoutes: [
        {   path: 'create', component: MessageFormContainer },
        {
            path: 'update/:id',
            component: MessageUpdatesContainer,
            childRoutes: [{
                path: 'infoCreate',
                component: InfoCreateContainer
            },{
                path: '/infoView/:id',
                component: InfoViewContainer
            }]
        }]
    }
  ]
}

Does not work. Only the URL is updated in the URL bar but nothing is rendered on the screen. The only change made to the component for Sample 2 is that they contain this.props.children tags to accommodate the childRoute components.

Any ideas would be helpful...thanks in advance!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!