Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

529
Visualizações
I can't render component with dynamic routes in react-router-dom@6

I intend to transfer this code that I found in a version prior to 6 in which Switch was still used to another with version 6.3.0 that I expose below and it returns me the following error:

!! Matched leaf route at location "/admin" does not have an element. This means it will render an with a null value by default resulting in an "empty" page.

and I can't render the component, I would appreciate a hand, thank you very much

import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

const routes = [
  {
    path: "/admin",
    element: <LayoutAdmin/>,
    routes: [
      {
        path: "/admin",
        element: <AdminHome/>,
      },
      {
        path: "/admin/login",
        element: <AdminSignIn/>,
      },
    ],
  },
];

function App() {
  return (
    <Router>
      <Routes>
        {routes.map((route, index) => (
          <RouteWithSubRoutes key={index} {...route} />
        ))}
      </Routes>
    </Router>
  );
}

function RouteWithSubRoutes(route) {
  console.log(route);
  return (
<Routes>
<Route path={route.path} render={(props) => <route.element routes={route.routes} {...props} />} />
</Routes>
  )
}

export default App;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

stack overflow answer

You can use the useRoutes hook from react router dom to nest routes.

about 4 years ago · Juan Pablo Isaza Relatório

0

Searching in this same forum I found what I needed to hear, to give up my attempt to do it like this: Properties such as children and render are already obsolete in v6, in this link there are more details, greetings – g.4 on Nov 24 2021 at 21:07

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda