Angular 8: Restore scroll position when browser back button is selected in child component

后端 未结 2 1073
独厮守ぢ
独厮守ぢ 2021-01-24 06:03

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 posit

2条回答
  •  长情又很酷
    2021-01-24 06:52

    I was able to make it work by adding

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

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

    And it worked 100%

提交回复
热议问题