2021-09-08 14:55:19 +08:00
|
|
|
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
2021-08-26 11:25:15 +08:00
|
|
|
import routeConfig from '@/config/routes';
|
|
|
|
|
2021-09-01 18:22:21 +08:00
|
|
|
const layoutModules = import.meta.glob('../Layouts/*');
|
2021-08-26 11:25:15 +08:00
|
|
|
const pagesModules = import.meta.glob('../pages/**/*.vue');
|
|
|
|
const fristPagesModules = import.meta.glob('../pages/*.vue');
|
|
|
|
const modules = Object.assign({}, layoutModules, fristPagesModules, pagesModules);
|
|
|
|
|
|
|
|
const getMenuRoutes = (list) => {
|
|
|
|
if (!list) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return list.map((item) => {
|
|
|
|
const { path = '', component, meta = { title: item.title }, redirect = '' } = item;
|
|
|
|
return {
|
|
|
|
path,
|
|
|
|
component: modules[component],
|
|
|
|
children: getMenuRoutes(item.children),
|
|
|
|
meta,
|
|
|
|
redirect,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const routes: Array<RouteRecordRaw> = [
|
|
|
|
...getMenuRoutes(routeConfig),
|
|
|
|
{
|
|
|
|
path: '',
|
|
|
|
redirect: '/dashboard/base',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const router = createRouter({
|
2021-09-08 14:55:19 +08:00
|
|
|
history: createWebHashHistory(),
|
2021-08-26 11:25:15 +08:00
|
|
|
routes,
|
2021-09-01 11:26:19 +08:00
|
|
|
scrollBehavior() {
|
2021-08-26 11:25:15 +08:00
|
|
|
return {
|
|
|
|
el: '#app',
|
|
|
|
top: 0,
|
|
|
|
behavior: 'smooth',
|
2021-09-01 11:26:19 +08:00
|
|
|
};
|
2021-08-26 11:25:15 +08:00
|
|
|
},
|
2021-09-01 11:26:19 +08:00
|
|
|
});
|
|
|
|
export default router;
|
2021-08-26 11:25:15 +08:00
|
|
|
|