重定向到页面刷新的其他组件

时间:2020-05-25 18:35:21

标签: reactjs react-hooks

在React中,如果用户刷新页面,有没有一种方法可以将用户重定向到首页?

当按下刷新按钮时,我可以触发警报,但是我无法设法真正重定向到关于页面(在这种情况下)。有什么想法吗?

  useEffect(() => {
    getWeather();

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

    };
  }, []);

1 个答案:

答案 0 :(得分:0)

useEffect(() => {
    getWeather();

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

    };
  }, []);