tdesign-vue-next-starter/src/router/index.ts
pengYYYYY f4c4cf7d9f fix/eslint (merge request !3)
Squash merge branch 'fix/eslint' into 'develop'
fix eslint error

Co-author: pengYYYYY <pengyue970715@gmail.com>
2021-09-01 03:31:48 +00:00

48 lines
1.1 KiB
TypeScript

import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import routeConfig from '@/config/routes';
const layoutModules = import.meta.glob('../layouts/*');
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',
component: () => import('@/pages/dashboard/base/index.vue'),
},
];
const router = createRouter({
history: createWebHistory(''),
routes,
scrollBehavior() {
return {
el: '#app',
top: 0,
behavior: 'smooth',
};
},
});
export default router;