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

146
Vistas
ReactJS: Redirect to homepage

I'm using react-router-dom, and I have a problem to redirect to the homepage (path="/").

Basically, I have a form with a submit button. When it is clicked I would to do the redirect.

const saveEntity = (event, errors, values) => {
    console.log('values .', values);
    if (values.realm) {
      setRealm(values.realm);
    }
    if (values.ente) {
      setEnte(values.ente);
    }
    if (values.realm) {
      console.log('dentro ', values.realm);
      // const history = useHistory();
      // const handler = () => {
      //   history.push('/');
      // };
      // return <Redirect to={{ pathname: '/' }} />;
    }
  };

return (
    <div>
      <AvForm  onSubmit={saveEntity}>
// .....

in the saveEntity I have tried to use history.push or Redirect, but nothing happens when I click the button.

How can I fix?

Thank you

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

0

You don't need to use a handler, just history.push('/'). and you have to call useHistory() in the root of YourComponent as bellow

const YourComponnt = ()=>{
const history = useHistory();

const saveEntity = (event, errors, values) => {
    console.log('values .', values);
    if (values.realm) {
      setRealm(values.realm);
    }
    if (values.ente) {
      setEnte(values.ente);
    }
    if (values.realm) {
      console.log('dentro ', values.realm);
    }

   history.push('/'); // or history.replace('/');
  };

return (
    <div>
      <AvForm  onSubmit={saveEntity}>
// .....
}
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