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

166
Views
React router how to go up with link to pathname

I am using the Link component from react router as follows

    <li><Link to={{
      pathname: "../photos",
      state: {
        id: props.id
      }
    }} className="nav-link active" >photos</Link></li>

I am using Link this way because I need to pass in some data to the linked component. The linked component exists on a route one level above the current route, hence the two dots and a slash ../ However, when clicked I'm not taken to a level above the current route, but rather /photos is appended to the end of the current route. If I use Link in this manner

<li><Link to="../photos" className="nav-link active" >photos</Link></li>

then it works as expected, but I am unable to pass data through. I don't understand why there is a discrepancy.

-----------------------EDIT--------------------------

Here is the solution Can not pass state with react router dom v6 beta, state is null

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

0

Use absolute path. For example;

pathname: "/dashboard/users/5/photos"
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!