scrollBehavior(to, from, savedPosition) {
// always scroll to top
return { top: 0 }
- }
+ },
})
```
```js
const router = createRouter({
- scrollBehavior (to, from, savedPosition) {
+ scrollBehavior(to, from, savedPosition) {
// always scroll 10px above the element #main
- // el: '#main'
- // could also be
- // el: document.getElementById('main'),
- return { el: '#main', top: -10 }
- }
+ return {
+ // could also be
+ // el: document.getElementById('main'),
+ el: '#main',
+ top: -10,
+ }
+ },
})
```
} else {
return { top: 0 }
}
- }
+ },
})
```
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return {
- el: to.hash
+ el: to.hash,
}
}
- }
+ },
})
```
resolve({ left: 0, top: 0 })
}, 500)
})
- }
+ },
})
```