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

293
Vistas
Nested routes react-router v6

I'm trying to make sense of some nested routes. I'm not sure if I set it up correctly

I have a component called Dashboard which will hold all content but if the path is not matched it will display a 404 page. When I try to hit /about it directs me to the 404 page all the time?

Edit react-router-v6 (forked)

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This is probably what you are looking for:

https://codesandbox.io/s/react-router-v6-forked-v6xtk

• As Muhammed Jaseem suggested — all your routes should be put in one component.

• It is also better practice to create one js/jsx component per page.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The routes are supposed to be defined in the app.js file.

I assume you want to serve the 'About' component when '/home/about' is hit. To achieve this you must nest the Route definitions like:

<Route path="/home" element={<Dashboard />}>
      <Route path='/about' element={<About />}/>
      <Route path='/contact' element={<Contact />} />
</Route>

Of course the 'About' and 'Contact' components need to be in their own files and imported the same way you imported the 'Dashboard' component.

Finally, the 'to' attributes of the 'Link' components in your Dashboard.js need to be changed to the full path for example '/home/about'.

about 4 years ago · Juan Pablo Isaza Denunciar

0

use

<Route path="/home/*" element={<Dashboard />} />

and

<Link to="contact" className="link">Contact</Link>

about 4 years ago · Juan Pablo Isaza Denunciar
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