Created
December 2, 2016 17:21
-
-
Save Granipouss/95f9a0a7323a52a3db09801134634a4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash' | |
import Vue from 'vue' | |
import Router from 'vue-router' | |
Vue.use(Router) | |
const routes = [] | |
const viewFiles = require.context('views', true, /\.vue$/) | |
viewFiles.keys().forEach(key => { | |
let view = viewFiles(key) | |
let name = key.replace(/(\.\/|\.vue)/g, '') | |
let options = view.routerOptions || {} | |
_.defaultsDeep(options, { | |
path: '/' + _.kebabCase(name), | |
params: '' | |
}) | |
routes.push({ | |
name, component: view, path: options.path + options.params | |
}) | |
}) | |
// import routes from 'src/routes' | |
_.merge(routes, require('src/routes').default) | |
console.log('Routes:', routes) | |
const router = new Router({ | |
scrollBehavior: () => ({ y: 0 }), | |
routes | |
}) | |
export default router |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment