路由器滚动页面可将新页面路由到顶部
我正在尝试实现一种方法,每当我更改页面时,它都会滚动到顶部。到目前为止,我尝试添加此信息:
useEffect(() => {
window.scrollTo(0, 0);
}, []);
但这无济于事。无论如何,是否可以这样做,以便每当通过React-Router打开新链接时,该应用都会自动升至顶部?我正在使用基于组件的功能,并且希望使用钩子的解决方案。
I am trying to implement a way where whenever I change a page, it scrolls to the top. So far, I have tried adding this:
useEffect(() => {
window.scrollTo(0, 0);
}, []);
But this does not help. Is there anyway to make it so whenever a new link is opened through react-router, the app automatically goes to the top? I am using component based functions and would prefer a solution that uses hooks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论