| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { App } from 'vue';
- import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
- import { RedirectRoute } from '@/router/base';
- import { PageEnum } from '@/enums/pageEnum';
- import { createRouterGuards } from './router-guards';
- import { exceptionRouters, HOME_PAGE, platformRoutes, RootRoute } from './full-routes';
- import { asyncImportRoute, routerGenerator } from './generator-routers';
- // const modules: any = import.meta.glob('./modules/**/*.ts', { eager: true });
- const routeModuleList: RouteRecordRaw[] = [];
- // Object.keys(modules).forEach((key) => {
- // const mod = modules[key].default || {};
- // const modList = Array.isArray(mod) ? [...mod] : [mod];
- // routeModuleList.push(...modList);
- // });
- function sortRoute(a, b) {
- return (a.meta?.sort || 0) - (b.meta?.sort || 0);
- }
- // routeModuleList.sort(sortRoute);
- const constantRoutes = [RootRoute, HOME_PAGE, RedirectRoute, exceptionRouters];
- //需要验证权限
- export const asyncRoutes = [...routeModuleList];
- const routeList = routerGenerator(constantRoutes);
- asyncImportRoute(routeList);
- //普通路由 无需验证权限
- export const constantRouter: any[] = routeList;
- export const router = createRouter({
- history: createWebHashHistory(),
- routes: constantRouter,
- strict: true,
- scrollBehavior(to) {
- if (to.hash) {
- return {
- el: to.hash,
- behavior: 'smooth',
- };
- }
- },
- });
- export function setupRouter(app: App) {
- app.use(router);
- // 创建路由守卫
- createRouterGuards(router);
- }
- export default router;
|