mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +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 %>')
|
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) => {
|
const scrollBehavior = (to, from, savedPosition) => {
|
||||||
// savedPosition is only available for popstate navigations.
|
// savedPosition is only available for popstate navigations.
|
||||||
if (savedPosition) {
|
if (savedPosition) {
|
||||||
@ -48,6 +51,7 @@ const scrollBehavior = (to, from, savedPosition) => {
|
|||||||
return position
|
return position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<% } %>
|
||||||
|
|
||||||
export default new Router({
|
export default new Router({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
|
@ -167,7 +167,8 @@ function * generateRoutesAndFiles () {
|
|||||||
isDev: this.dev,
|
isDev: this.dev,
|
||||||
router: {
|
router: {
|
||||||
base: this.options.router.base,
|
base: this.options.router.base,
|
||||||
linkActiveClass: this.options.router.linkActiveClass
|
linkActiveClass: this.options.router.linkActiveClass,
|
||||||
|
scrollBehavior: this.options.router.scrollBehavior
|
||||||
},
|
},
|
||||||
env: this.options.env,
|
env: this.options.env,
|
||||||
head: this.options.head,
|
head: this.options.head,
|
||||||
|
@ -38,7 +38,8 @@ class Nuxt {
|
|||||||
router: {
|
router: {
|
||||||
base: '/',
|
base: '/',
|
||||||
linkActiveClass: 'nuxt-link-active',
|
linkActiveClass: 'nuxt-link-active',
|
||||||
extendRoutes: null
|
extendRoutes: null,
|
||||||
|
scrollBehavior: null
|
||||||
},
|
},
|
||||||
build: {}
|
build: {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user