再layout组件中添加//解决页面不自动跳转顶部
useEffect(() => {
if (document && history?.location?.pathname != '/home') {
// 可以排除不需要置顶的页面
if (document?.documentElement || document?.body) {
document.documentElement.scrollTop = document.body.scrollTop = 0; // 切换路由时手动置顶
}
}
}, [history?.location?.pathname]);
react的函数式组件的路由跳转不自动到顶部解决
最新推荐文章于 2022-06-22 03:14:37 发布