Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
How to redirect in react if the user logged in

Well before writing this question i have searched internet Basically it shows 3 solution i tried all they seems to be outdated

1. using history.push('/')

The problem i am facing with this method is that browser saying who the hell is push i dont know what she is to debug i try to console history i find it is undefined i have seen in the answer they

I am just copying their answers

import { useHistory } from "react-router-dom"

function HomeButton() {
  let history = useHistory()

  function handleClick() {
    history.push("/home")
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  )
}

but this does not work because useHistory import error it is outdated the other answers also is not usable like done with redirect again having import error

Please suggest me a good way to do this

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

history is depreciated since react-router version 6+, if you want to migrate then follow this link.

If you however freshly installed version 6+ then you can use useNavigate

import { useNavigate } from "react-router-dom";

function HomeButton() {
  let navigate = useNavigate()

  function handleClick() {
     navigate("/home")
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  )
}

more on the topic here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda