chore: minor olishes

This commit is contained in:
Pooya Parsa 2017-07-10 03:10:09 +04:30
parent 5da4e49d56
commit a9f2f299a3
2 changed files with 10 additions and 14 deletions

View File

@ -1,5 +1,3 @@
'use strict'
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
@ -7,7 +5,7 @@ Vue.use(Router)
<% <%
function recursiveRoutes(routes, tab, components) { function recursiveRoutes(routes, tab, components) {
var res = '' let res = ''
routes.forEach((route, i) => { routes.forEach((route, i) => {
route._name = '_' + hash(route.component) route._name = '_' + hash(route.component)
components.push({ _name: route._name, component: route.component, name: route.name }) components.push({ _name: route._name, component: route.component, name: route.name })
@ -20,31 +18,30 @@ function recursiveRoutes(routes, tab, components) {
}) })
return res return res
} }
var _components = [] const _components = []
var _routes = recursiveRoutes(router.routes, '\t\t', _components) const _routes = recursiveRoutes(router.routes, '\t\t', _components)
uniqBy(_components, '_name').forEach((route) => { %> uniqBy(_components, '_name').forEach((route) => { %>const <%= route._name %> = () => import('<%= relativeToBuild(route.component) %>' /* webpackChunkName: "pages/<%= route.name %>" */).then(m => m.default || m)
const <%= route._name %> = () => import('<%= relativeToBuild(route.component) %>' /* webpackChunkName: "pages/<%= route.name %>" */).then(m => m.default || m)
<% }) %> <% }) %>
<% if (router.scrollBehavior) { %> <% if (router.scrollBehavior) { %>
const scrollBehavior = <%= serialize(router.scrollBehavior).replace('scrollBehavior(', 'function(') %> const scrollBehavior = <%= serialize(router.scrollBehavior).replace('scrollBehavior(', 'function(') %>
<% } else { %> <% } 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) {
return savedPosition return savedPosition
} else { } else {
let position = {} let position = {}
// if no children detected // If no children detected
if (to.matched.length < 2) { if (to.matched.length < 2) {
// scroll to the top of the page // Scroll to the top of the page
position = { x: 0, y: 0 } position = { x: 0, y: 0 }
} }
else if (to.matched.some((r) => r.components.default.options.scrollToTop)) { else if (to.matched.some((r) => r.components.default.options.scrollToTop)) {
// if one of the children has scrollToTop option set to true // If one of the children has scrollToTop option set to true
position = { x: 0, y: 0 } position = { x: 0, y: 0 }
} }
// if link has anchor, scroll to anchor by returning the selector // If link has anchor, scroll to anchor by returning the selector
if (to.hash) { if (to.hash) {
position = { selector: to.hash } position = { selector: to.hash }
} }
@ -61,7 +58,7 @@ export function createRouter () {
linkExactActiveClass: '<%= router.linkExactActiveClass %>', linkExactActiveClass: '<%= router.linkExactActiveClass %>',
scrollBehavior, scrollBehavior,
routes: [ routes: [
<%= _routes %> <%= _routes %>
], ],
fallback: <%= router.fallback %> fallback: <%= router.fallback %>
}) })

View File

@ -1,4 +1,3 @@
'use strict'
import Vue from 'vue' import Vue from 'vue'
const noopData = () => ({}) const noopData = () => ({})