Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda