2016-11-10 02:38:11 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-11-07 01:34:58 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Router from 'vue-router'
|
|
|
|
|
|
|
|
Vue.use(Router)
|
|
|
|
|
2016-11-20 11:23:48 +00:00
|
|
|
<% uniqBy(router.routes, '_name').forEach((route) => { %>
|
2016-11-24 00:47:11 +00:00
|
|
|
const <%= route._name %> = process.BROWSER_BUILD ? () => System.import('<%= route._component %>') : require('<%= route._component %>')
|
2016-11-07 01:34:58 +00:00
|
|
|
<% }) %>
|
|
|
|
|
|
|
|
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',
|
2016-11-10 16:16:37 +00:00
|
|
|
base: '<%= router.base %>',
|
|
|
|
linkActiveClass: '<%= router.linkActiveClass %>',
|
2016-11-07 01:34:58 +00:00
|
|
|
scrollBehavior,
|
|
|
|
routes: [
|
2016-11-10 16:16:37 +00:00
|
|
|
<% router.routes.forEach((route, i) => { %>
|
2016-11-07 01:34:58 +00:00
|
|
|
{
|
|
|
|
path: '<%= route.path %>',
|
2016-11-07 20:38:51 +00:00
|
|
|
component: <%= route._name %><% if (route.name) { %>,
|
2016-11-08 00:04:26 +00:00
|
|
|
name: '<%= route.name %>'<% } %><% if (route.meta) { %>,
|
|
|
|
meta: <%= JSON.stringify(route.meta) %><% } %>
|
2016-11-10 16:16:37 +00:00
|
|
|
}<%= (i + 1 === router.routes.length ? '' : ',') %>
|
2016-11-07 01:34:58 +00:00
|
|
|
<% }) %>
|
|
|
|
]
|
|
|
|
})
|