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

945
Views
this.props.match.params.id in React.js is undefined

I want to get the id from the URL therefore I can use this id to get and output the user info but I can't get id from URL. I've seen useParams() but I think it is not applicable with class component. May I know if there is an alternative solution for this?

 async componentDidMount(){
    const stud_id = this.props.match.params.id;
    console.log(stud_id);
 }

see error message from console here

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

0

If you're using

<Route path="/blah" component={()=><YourComponent someProp={someProp}>}/>

I mean, with arrow function as it child component, you have to pass the pros of the father (Route) to the child (YourComponent) like that:

<Route path="/blah" component={({match})=><YourComponent match={match} someProp={someProp}>}/>

Because you're creating a new "generation" so you have to pass the props by your self

about 4 years ago · Juan Pablo Isaza Report

0

The most common way of reading URL params in React is using React Router. In React Router, you get URL params with this.props.match.params like you are trying to, but you have to call your component inside a Route, like for example:

<Route 
  path="/:id" 
  component={YourComponent} 
/>

instead of just

<YourComponent />

So that your component receives the match prop and can access this.props.match.params.id

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!