我正在使用 scrollrestoration
Next.js的功能来恢复页面位置时按下返回按钮。问题是,它不会恢复该页面上旋转木马的水平滚动位置。因此,我创建了自己的会话变量来跟踪每个轮播的位置并在页面加载中还原它们。问题是,如果按下背面/向前按钮,我只想恢复这些滚动位置。如果有一个指标表明 scrollrestoration
在页面上使用了,则可以使用该页面,否则,如果有迹象表明该页面是使用也可以解决该页面的forward/back按钮访问的。
有什么想法吗?
I am using the scrollRestoration
feature of Next.js to restore the page position when a back button is pressed. The problem, is that it doesn't restore the horizontal scroll position of the carousels on that page. So I have created my own session variables to track the position of each carousel and restore them on page load. The problem, is that I ONLY want to restore these scroll positions if the back/forward button was pressed. If there is an indicator that scrollRestoration
was used on the page I could use that, otherwise, if there is an indication that the page was visited using the forward/back buttons that would also solve it.
Any ideas?
发布评论
评论(2)
我已经弄清楚了如何确定是否为页面设置了卷轴。
i have figured out how to determine if scrollRestoration is set for a page.
从来没有这样做,但是我的本能是:
useffect
在 router.pathname 更改围绕框架的这种方式,但看起来下一步并不像您要寻找的东西。
Never done this but my instinct would be:
useEffect
that updates on router.pathName changesThat kind of goes around the framework, but it doesn't look like Next exposes what you're looking for.