Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda