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

153
Vistas
React Router goBack does not work on buttonclick

I want to be able to go back to the previous page (just like using the back button in the browser), so I tried using useHistory's goBack(), but it does not work.

I imported useHistory:

import {
  BrowserRouter,
  Route,
  useHistory
} from "react-router-dom";

I wrote this function:

function GoBack(){
  const history = useHistory();

  return (
    <>
      <button onClick={() => history.goBack()}>Back</button>
    </>
);
}

I get this error:

TypeError: Cannot read properties of undefined (reading 'goBack')

This calls GoBack:

  function App() {
  const [user] = useAuthState(auth);
  return (
    <div className="App">
      <header className="App-header">
        <GoBack />
      </header>
      <section>{user ? <ChatRoom /> : <SignIn />}</section>
    </div>
  );
}

How can I fix this problem?

about 4 years ago · Juan Pablo Isaza
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