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

528
Views
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 answers
Answer question

0

stack overflow answer

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

about 4 years ago · Juan Pablo Isaza Report

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 Report
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!