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

72
Vistas
react-router-dom return undefined when second history.push is triggered

Hi have the following Antd modal:

<Modal visible={visible} onOk={handleOk} onCancel={handleCancel}>
  <MyForm onSubmit={handleOpenUrl}>
      <CustomInput
        name="input"
        onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
          handleInput(event, "input")
        }
      />
      <Button type="submit" >
        Submit
      </Button>
  </MyForm>
</Modal>;

And I have the following handler for this form:

const handleInput = (event: React.SyntheticEvent) => {
  event.preventDefault();
  // other operation where checked is handled...
  history.push({
    pathname: "/",
    search: "?" + new URLSearchParams({ datas: checked }).toString(),
  });
};

the weird thing is that when I open the form and I submit the form for the first time it update the url and add it like the following: http://localhost:3000/?datas=myqueryparams but when I do it for the second time it says: TypeError: Cannot read properties of undefined (reading 'push')

Any ideas about that?

UPDATE

for app component I have added the following:

<Switch>
          <Route path="/?datas=:datas" exact component={App} />
          <Route path="/" exact component={App} />
        </Switch>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

have you wrapped the app component with BrowserRouter from react-router-dom ? example code like this

import React from "react";
import {
  BrowserRouter as Router
} from "react-router-dom";

export default function App() {
  return (
    <Router>
     <ChildComponent />
    </Router>
  );
}
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