Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

946
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda