再layout组件中添加

  //解决页面不自动跳转顶部

  useEffect(() => {

    if (document && history?.location?.pathname != '/home') {

      // 可以排除不需要置顶的页面

      if (document?.documentElement || document?.body) {

        document.documentElement.scrollTop = document.body.scrollTop = 0; // 切换路由时手动置顶

      }

    }

  }, [history?.location?.pathname]);

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐