Skip to content

Instantly share code, notes, and snippets.

@Granipouss
Created December 2, 2016 17:21
Show Gist options
  • Save Granipouss/95f9a0a7323a52a3db09801134634a4a to your computer and use it in GitHub Desktop.
Save Granipouss/95f9a0a7323a52a3db09801134634a4a to your computer and use it in GitHub Desktop.
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