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

132
Views
How to add sub paths in react router

I have a index file where I have

<BrowserRouter>
  <Routes>
    <Route path="/" element={Home}
    <Route path="/home/student/info" element={Info} />
    <Route path="/home/student/about" element={about} />
    <Route path="/home/teacher/score" element={score} />
    <Route path="/home/teacher/attendence" element={attendence} />
  </Routes>
</BrowserRouter>

Here, I have this common path for "/home/student/". So How can I use a react sub path for this, rather than writing separate lines? I'm using react-router 6.

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

0

You can use nested routes. Put routes as children of the route component. Don't forget that in RRDv6 the element prop takes a ReactNode, e.g. JSX, and not a reference to a React component like v5.

<BrowserRouter>
  <Routes>
    <Route path="/" element={<Home />} />
    <Route path="home">
      <Route path="student">
        <Route path="info" element={<Info />} />
        <Route path="about" element={<About />} />
      </Route>
      <Route path="teacher">
        <Route path="score" element={<Score />} />
        <Route path="attendence" element={<Attendence />} />
      </Route>
    </Route>
  </Routes>
</BrowserRouter>

You can read more about nested routes here.

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!