Skip to content

Instantly share code, notes, and snippets.

@Mohammad-Alavi
Created May 2, 2021 09:11
Show Gist options
  • Save Mohammad-Alavi/4bae9e72d927c91fc699cd50352448d8 to your computer and use it in GitHub Desktop.
Save Mohammad-Alavi/4bae9e72d927c91fc699cd50352448d8 to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// Define base routes here
const baseRoutes = [
{
path: '/',
name: 'index',
redirect: { name: 'home' }
},
{
path: '*',
redirect: '/404'
}
]
// Import all of the resource routes files.
function loadRoutes () {
const context = require.context('@/modules', true, /routes/index.js$/i)
return context.keys()
.map(context) // import module
.map(m => m.default) // get `default` export from each resolved module
}
const resourceRoutes = loadRoutes()
resourceRoutes.forEach((route) => {
for (let i = 0; i < route.length; i++) {
baseRoutes.push(route[i])
}
})
const router = new VueRouter({
mode: 'history',
// base: process.env.BASE_URL,
// linkActiveClass: 'active',
scrollBehavior () {
return { x: 0, y: 0 }
},
routes: baseRoutes
})
export default router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment