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

287
Views
Nested routes react-router v6

I'm trying to make sense of some nested routes. I'm not sure if I set it up correctly

I have a component called Dashboard which will hold all content but if the path is not matched it will display a 404 page. When I try to hit /about it directs me to the 404 page all the time?

Edit react-router-v6 (forked)

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

0

This is probably what you are looking for:

https://codesandbox.io/s/react-router-v6-forked-v6xtk

• As Muhammed Jaseem suggested — all your routes should be put in one component.

• It is also better practice to create one js/jsx component per page.

about 4 years ago · Juan Pablo Isaza Report

0

The routes are supposed to be defined in the app.js file.

I assume you want to serve the 'About' component when '/home/about' is hit. To achieve this you must nest the Route definitions like:

<Route path="/home" element={<Dashboard />}>
      <Route path='/about' element={<About />}/>
      <Route path='/contact' element={<Contact />} />
</Route>

Of course the 'About' and 'Contact' components need to be in their own files and imported the same way you imported the 'Dashboard' component.

Finally, the 'to' attributes of the 'Link' components in your Dashboard.js need to be changed to the full path for example '/home/about'.

about 4 years ago · Juan Pablo Isaza Report

0

use

<Route path="/home/*" element={<Dashboard />} />

and

<Link to="contact" className="link">Contact</Link>

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!