Created
May 2, 2021 09:11
-
-
Save Mohammad-Alavi/4bae9e72d927c91fc699cd50352448d8 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 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