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

198
Vistas
How to realize <Route children={({match})} => ... /> in a react-router-dom v6?

I have a modal which depended on a url.

my modal in jsx

<Route
    path={`/preview/${params.id}`}
    children={({match}) => {
        return (
            <ModalWindow
                modalVisible={Boolean(match)}
                onCloseWindow={onCloseWindow}
                modalContent={modal}
            />
        )
    }}
/>

I am getting an error A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.

But I already wrapped all my app in a tag.

export default function AppRouter() {
  return (
    <Routes>
        <Route 
            path={"/home"}
            element={<HomeApp />}
        />
        <Route 
            path={"/preview/:id"}
            exact
            element={<HomeApp />}
        />
         <Route
            path={"/fullInfo/:id"}
            exact
            element={<HomeApp />}
         />
        <Route
            path={"*"}
            render={<Navigate to="/home"/>}
        />
    </Routes>
  )
}

P.s I am new in react-router-dom of the new version.

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

0

You have to wrap the rendered element in the element prop of your Route.So instead of :

 <Route
      path={"*"}
      render={<Navigate to="/home"/>}
  />

Do this:

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

It is the same for the modal Route, you should wrap the component in the element prop of the Route

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