Redirect to other component on page refresh

Viewed 742

Is there a way, in React, to redirect the user to, let's say, the homepage, if the user refreshes the page?

I can trigger an alert when the refresh button is pressed, but I cannot manage to actually redirect to the about-page (in this case). Any ideas?

  useEffect(() => {
    getWeather();

    return () => {
      if (window.performance.navigation.type == 1) {
        alert("Redirect")
        return <Redirect to="/About"></Redirect>
      }

    };
  }, []);
1 Answers
useEffect(() => {
    getWeather();

    return () => {
      if (window.performance.navigation.type == 1) {
         window.location.href = "/About"
      }

    };
  }, []);
Related