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

79
Views
React pass information to child of Route

I am building a react navigation and have to pass info to the sidenav. Therefore I have to pass props to my body, but the body is rendered by a router and I can't just pass them. I have seen a lot on this, but always with self-closing tags, so that you can just paste the props in the render function of the Route. Below the code:

App.js

function App() {
//...
return (
<Router>

  <Switch>
    {Object.keys(routesGroupedByLayouts).map(layoutName => {
      const LayoutTag = layouts[layoutName];
      const layoutRoutes = routesGroupedByLayouts[layoutName].map(route => route.path);

      return <Route key={`layout-${layoutName}`} exact={true} path={layoutRoutes} render={() => {
        return (
          <ScrollToTop>
            <LayoutTag>
              <h1>sdsdddscxcxs</h1>
              <Switch>
                {routesGroupedByLayouts[layoutName].map(route => (
                  <Route key={route.path}
                         path={route.path}
                         exact={route.exact === true}
                         render={() => <route.component fallback={<Loading />} />} />
                ))}
              </Switch>
            </LayoutTag>
          </ScrollToTop>
        )
      }} />
    })}
  </Switch>
</Router>
);
}

default.jsx

const Default = ({children}) => {
//...
return (
    <Layout>
      <Layout.Body id={"main-content"}>
        <div>
          {children}
        </div>
      </Layout.Body>
    </Layout>
  )
}

I hope I pasted everything needed here. So the LayoutTag passes the children to the default.jsx, but I don't know how to pass the children to the rendered Body of the Route element. I have to pass the body a function that executes in default.

Hope somebody can help me out, thanks in advance!

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