Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!