Add scrollBehavior option

This commit is contained in:
Sébastien Chopin 2017-01-26 15:56:47 +01:00
parent 68426b4df4
commit d9fe4b9612
3 changed files with 8 additions and 2 deletions

View File

@ -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',

View File

@ -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,

View File

@ -38,7 +38,8 @@ class Nuxt {
router: {
base: '/',
linkActiveClass: 'nuxt-link-active',
extendRoutes: null
extendRoutes: null,
scrollBehavior: null
},
build: {}
}