How to modify default router scroll behavior #2197
-
Story: Scenario:
Expected behavior:
Current behavior:
Now, if at step 2., before I return to home page, I first scroll back to the I would expect the router to remember the home screen position and scroll to the bottom at I have disabled this behavior by hardwiring the scrolling behavior to always get back to the top of the screen at
As you can see, this is not perfect. How do I get the wanted behavior, which is to let the router remember the correct page position when returning to the home page, and not go to the wrong position when visiting the detail page? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use it to do the following: scrollBehavior(_to, _from, savedPosition) {
return savedPosition || { top: 0 }
}
This is described on this page, written in a slightly different (but equivalent) way: https://router.vuejs.org/guide/advanced/scroll-behavior.html |
Beta Was this translation helpful? Give feedback.
scrollBehavior
third argument stores the saved scrolling position.You can use it to do the following:
savedPosition
isnull
so it will scroll to the topsavedPosition
is used insteadThis is described on this page, written in a slightly different (but equivalent) way: https://router.vuejs.org/guide/advanced/scroll-behavior.html