Previous Behavior:
Changing the route or navigation path would not affect the scroll position when navigating to another route. I.e the contents can change without the scroll position changing.
Current Behavior:
Changing the route will put you right back to the top of the page.
Action Done So Far:
Tested on current and a fresh new Angular 6 project
Is this a bug? change in feature? or is there a parameter I am missing.
Preserve scroll position allows you to maintain the same scroll location when you transition between two screens. This applies to scroll depth in a vertical scroll, as well as the user's location inside a horizontal scrolling element. Figma automatically preserves your scroll position for Smart Animate.
store the position in cookies and after that use the cookie to scroll the page to exact position .
ng-scrolltop demo: angular component that monitors current Y position in a long page or element then if scrolled down enough, shows up a clickable, unobtrusive icon that scrolls to top smoothly.
The scroll position won't change after the route is changed. This is always the default behaviour for Angular.
However, lots of devs are manually doing a window.scroll(0, 0)
to overwrite this behaviour.
I would suggest you check if something in your code is doing this. Because it might be a newly installed 3rd party library or another developer's code commit.
Also, according to the following official article:
Angular v6.1 Now Available — TypeScript 2.9, Scroll Positioning, and more
There is a new option to keep the original scroll position by using
RouterModule.forRoot(routes, {scrollPositionRestoration: 'enabled'})
I believe this is not directly related to the question you are asking but just something good to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With