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

157
Views
Pass props to child component through Route in react-router-dom in Function Component

My current Home component snippet is:

function Home() {
  return (
    <div>
      <AddTaskForm
        ailDivision={ailDivision}
        ascDivision={ascDivision}
        apcDivision={apcDivision}
      />
      <UpdateTaskForm
        ailDivision={ailDivision}
        ascDivision={ascDivision}
        apcDivision={apcDivision}
      />
      <EtaFetch />
    </div>
  );
}
export default Home;

But I want these components to have individual routes, using react-router-dom like:

function Home() {
  return (
    <div>
      <Routes>
        <Route path="/addtask" exact element={<AddTaskForm/>} />
        <Route path="/updatetask" exact element={<UpdateTaskForm/>} />
        <Route path="/etafetch" exact element={<EtaFetch/>} />
      </Routes>
    </div>
  );
}

My question is: How do I pass props to the Route components in the second snippet?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The routed components are rendered as JSX, so passing props works as normal in React.

Example:

function Home() {
  return (
    <div>
      <Routes>
        <Route
          path="/addtask"
          element={(
            <AddTaskForm
              ailDivision={ailDivision}
              ascDivision={ascDivision}
              apcDivision={apcDivision}
            />
          )}
        />
        <Route
          path="/updatetask"
          element={(
            <UpdateTaskForm
              ailDivision={ailDivision}
              ascDivision={ascDivision}
              apcDivision={apcDivision}
            />
          )}
        />
        <Route path="/etafetch" element={<EtaFetch />} />
      </Routes>
    </div>
  );
}
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!