I need to detecta a page refresh and redirect the user to another page if a page has been refreshed. I am trying this option but it seems it is not the right way to do it. Firstly, because it seems the performance.navigation.type is deprecated and secondly, I am using multiple effect hooks here, which I am not sure if that is correct, Any ideas for a more elegant solution?
const EligibilityPage = () => {
const [hasRouteChanged, sethasRouteChanged] = useState(false);
const location = useLocation();
useEffect(() => {
sethasRouteChanged(true);
}, [location]);
useEffect(() => {
if (window.performance) {
if (window.performance.navigation.type == "reload" || window.performance.navigation.type == 1) {
if (!hasRouteChanged) window.location.href = "/personal-details-page";
}
}
}, []);