角度8:在子组件中选择了“浏览器后退"按钮时,还原滚动位置 [英] Angular 8: Restore scroll position when browser back button is selected in child component

查看:95
本文介绍了角度8:在子组件中选择了“浏览器后退"按钮时,还原滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多卡列表的组件(例如网格格式).向下滚动并选择其中一张卡后,当我按下浏览器的后退按钮时,我希望会回到相同的滚动位置.

I have a component consisting of a list of many cards (like a grid format). Upon scrolling down and selecting one of the cards, I would expect to return to the same scroll position when I press the browser back button.

我无法使用Router的scrollPositionRestoration方法,因为它位于我的子组件中.

I'm unable to use Router's scrollPositionRestoration method as it is located in my child component.

感谢您的帮助!

推荐答案

我能够通过添加

{scrollPositionRestoration:'top'}到RouterModule.forRoot(routes)像这样:

{ scrollPositionRestoration: 'top' } to the RouterModule.forRoot(routes) like this:

RouterModule.forRoot(routes, { scrollPositionRestoration: 'top' })

它成功了100%

这篇关于角度8:在子组件中选择了“浏览器后退"按钮时,还原滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆