title: Vue Router - Change anchor in route on scroll
body: <p>I am basically trying to have the exact same routing behaviour on my site as here: <a href="https://router.vuejs.org/guide/#html" rel="noreferrer">https://router.vuejs.org/guide/#html</a>.
  Notice when you scroll down the link changes to <a href="https://router.vuejs.org/guide/#javascript" rel="noreferrer">https://router.vuejs.org/guide/#javascript</a>. Scroll back up and it is vice versa. When reloading the page your position gets saved.</p>
  
  <p>I added the following scroll behavior to my router:</p>
  
  <pre><code>  scrollBehavior(to, from, savedPosition) {
      if (to.hash) {
          return { selector: to.hash }
      } else if (savedPosition) {
          return savedPosition;
      } else {
          return { x: 0, y: 0 }
      }
  
  </code></pre>
  
  <p>Now I can jump to an anchor with a link and the route changes. That's about as far as I get. Kind of ironic to pick the Vue Router website as an example, but anyway - how can I replicate its behaviour?</p>