why VueJs router savedPosition for scrollBehavior

2019-07-27 10:33发布

I use vue-router 2.5.3 and have two pages: first for long list (loaded via ajax) and second for details.

When I scroll down on list page and next navigate using clicking back the browser button the browser always scrolls to the top. The value of savedPosition is for the first time undefined and for next attempts Object {x: 0, y: 0}

<div class="main-content">
  <router-view ></router-view>
</div>

scrollBehavior(to, from, savedPosition) {
    console.info(savedPosition) // first attemp undefined and next  always {x: 0, y: 0} regardless previous position

    if (savedPosition) {
      return savedPosition
    } else if (to.name == from.name) 
    {
      return
    }
    else {
      return { x: 0, y: 0 }
    }
  },
  mode: 'history',

what is savedPosition and how it is triggered ?

0条回答
登录 后发表回答