mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-08 01:42:38 +00:00
39 lines
965 B
JavaScript
39 lines
965 B
JavaScript
|
import Vue from 'vue'
|
||
|
import Router from 'vue-router'
|
||
|
import Meta from 'vue-meta'
|
||
|
|
||
|
Vue.use(Router)
|
||
|
Vue.use(Meta)
|
||
|
|
||
|
<% routes.forEach(function (route) { %>
|
||
|
const <%= route._name %> = process.BROWSER ? () => System.import('<%= route._component %>') : require('<%= route._component %>')
|
||
|
<% }) %>
|
||
|
|
||
|
const scrollBehavior = (to, from, savedPosition) => {
|
||
|
if (savedPosition) {
|
||
|
// savedPosition is only available for popstate navigations.
|
||
|
return savedPosition
|
||
|
} else {
|
||
|
// Scroll to the top by default
|
||
|
let position = { x: 0, y: 0 }
|
||
|
// if link has anchor, scroll to anchor by returning the selector
|
||
|
if (to.hash) {
|
||
|
position = { selector: to.hash }
|
||
|
}
|
||
|
return position
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default new Router({
|
||
|
mode: 'history',
|
||
|
scrollBehavior,
|
||
|
routes: [
|
||
|
<% routes.forEach((route, i) => { %>
|
||
|
{
|
||
|
path: '<%= route.path %>',
|
||
|
component: <%= route._name %>
|
||
|
}<%= (i + 1 === routes.length ? '' : ',') %>
|
||
|
<% }) %>
|
||
|
]
|
||
|
})
|