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

319
Visualizações
How to detect page refresh on react

I've been stuck on this for hours, how can I detect a page refresh and reroute the user to a specific path? /error for example

I'm using useNavigate for rerouting, it works but I dont know how to properly listen for a page refresh

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

here is what you need in this example. In fact, with this method you can detect if that page has refreshed or reloaded, so you can use the useEffect and performance.

You use the method navigate to be able to navigate the pages. Don't forget if you have any state you can include it in the dependency array of the useEffect().

import React, { useEffect } from "react";

export default function NavigationDectector() {
  const { navigate} = useNavigate();
  useEffect(() => {
    if (performance.navigation.type === 1) {
      console.log("This page is reloaded");
      // here you can navigate 
    } else {
      console.log("This page is not reloaded");
    }
    // if you have any state which you depend on the reload put it in the 
    array of the use effect
  },[]);

  return <div></div>;
}

I hope this can helps you

about 4 years ago · Santiago Gelvez Relatório
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