mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Add scrollBehavior option
This commit is contained in:
parent
68426b4df4
commit
d9fe4b9612
@ -26,6 +26,9 @@ uniqBy(_components, '_name').forEach((route) => { %>
|
||||
const <%= route._name %> = process.BROWSER_BUILD ? () => System.import('<%= route.component %>') : require('<%= route.component %>')
|
||||
<% }) %>
|
||||
|
||||
<% if (router.scrollBehavior) { %>
|
||||
const scrollBehavior = <%= serialize(router.scrollBehavior).replace('scrollBehavior(', 'function(') %>
|
||||
<% } else { %>
|
||||
const scrollBehavior = (to, from, savedPosition) => {
|
||||
// savedPosition is only available for popstate navigations.
|
||||
if (savedPosition) {
|
||||
@ -48,6 +51,7 @@ const scrollBehavior = (to, from, savedPosition) => {
|
||||
return position
|
||||
}
|
||||
}
|
||||
<% } %>
|
||||
|
||||
export default new Router({
|
||||
mode: 'history',
|
||||
|
@ -167,7 +167,8 @@ function * generateRoutesAndFiles () {
|
||||
isDev: this.dev,
|
||||
router: {
|
||||
base: this.options.router.base,
|
||||
linkActiveClass: this.options.router.linkActiveClass
|
||||
linkActiveClass: this.options.router.linkActiveClass,
|
||||
scrollBehavior: this.options.router.scrollBehavior
|
||||
},
|
||||
env: this.options.env,
|
||||
head: this.options.head,
|
||||
|
@ -38,7 +38,8 @@ class Nuxt {
|
||||
router: {
|
||||
base: '/',
|
||||
linkActiveClass: 'nuxt-link-active',
|
||||
extendRoutes: null
|
||||
extendRoutes: null,
|
||||
scrollBehavior: null
|
||||
},
|
||||
build: {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user