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

262
Visualizações
React- this.props.history.push('pathname') does not work?

I am currently writing a small CRUD application. For my frontend I am using React v6. In my code I have a list of the Entity and above that I would have a button that takes me to a form that lets me add a new entry in the table. However, Even though I have routed the different URLs, after clicking the button I just get an error saying: Cannot read properties of undefined (reading 'push')

The lines of code in question are:

addContractor() {
        this.props.history.push("/add-contractor");
    }

In my App.js file I have the appropriate routing as well:

<Route path="/add-contractor" element = {<CreateContractorComponent/>}/>

I am not sure why this is happening and I would like some insight and explanation as I am very new to frontend development.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I guess the problem is with nested components, try nesting the Switch without wrapping it with a BrowserRouter in App.js file.

If it doesn't work try this alternative too, Might be a few things that have changed in the documentation. Import useNavigate instead of useHistory and for reference go through this blog - https://reacttraining.com/blog/react-router-v6-pre/

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