问题
I'm on page 1, I scroll halfway through the page and then click a link that brings me to page 2 through the Angular router. When I hit the "back" button, I'd like page 1 to be scrolled halfway down, just like it was before I left that page.
What is the easiest way to do that?
回答1:
Save to localStorage
scroll position in ngOnDestroy()
, and restore it in ngOnInit()
来源:https://stackoverflow.com/questions/42439745/how-to-make-angular-2-remember-scroll-position