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

232
Vistas
How to block rerouting with history

in our project we are using React Router and history package to manage routes. We are also using xstate for our state managment. I would like to know if it is possible not only to detect route changes with history package but also to block re-routing to another page in case there are any unsaved parameters. This is my piece of code I am working with right now :

  React.useEffect(() => {
    history.listen((location, action) => {
      if(location.pathName === '/master')
      {
        history.block()
        send('ROUTE_CHANGE_INITIATED')
      }
    })
  }, [])

But this only blocks rerouting after the route has already change for example I leave the page that I shouldn't leave and then is rerouting blocked. What I am trying to do is to block the reroute before the route actually changes. Is this even possible from within component? I would not like to add this code to <Route /> components or even higher in the hierarchy.

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