123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
- import { app_ready, app_routes } from '~/store/app';
- import { RouteRecordDetailRaw } from './routes.d';
- import localRoutes, { title } from './routes/xdjx';
- // import localRoutes, { title } from './routes/xdjy';
- // import localRoutes, { title } from './routes/xdhq';
- document.title = title
- // !auto switch routes way 1:
- // !build error
- // const localRoutes = (await import(`./routes/${import.meta.env.MODE}.ts`))['default'] as RouteRecordDetailRaw[]
- // const currentRouteModule = import.meta.glob(`./routes/*.ts`, { eager: true })[`./routes/${import.meta.env.MODE}.ts`] as { title: string, default: RouteRecordDetailRaw[] }
- // document.title = currentRouteModule['title']
- // const localRoutes = currentRouteModule['default']
- console.log('localRoutes :>> ', localRoutes);
- const router = createRouter({
- history: createWebHashHistory(),
- routes: [
- {
- path: '/',
- component: () => import("~/layout/loading/index.vue")
- },
- {
- path: '/routes',
- name: '-ROUTES',
- props: true,
- meta: {
- hidden: false,
- sort: -1,
- title: "组织机构与权限"
- },
- component: () => import("~/router/routes.vue")
- },
- {
- path: '/xxzx',
- name: 'xxzx',
- props: true,
- meta: {
- hidden: true,
- sort: -1,
- title: "消息中心"
- },
- component: () => import("~/pages/[...]/xxzx/index.vue")
- }
- ]
- })
- export default router
- async function handleFilterRoutes<R extends RouteRecordDetailRaw[]>(routes: R): Promise<Partial<R>> {
- console.log(' handleFilterRoutes ');
- await new Promise((resolve) => {
- setTimeout(() => {
- resolve(routes)
- }, 0);
- })
- return [...routes] as Partial<R>
- }
- const routes = await handleFilterRoutes(localRoutes)
- sessionStorage.setItem('routes', JSON.stringify(routes.concat([{
- path: '/routes',
- name: '-ROUTES',
- meta: {
- hidden: false,
- sort: -1,
- title: "组织机构与权限"
- },
- component: () => import("~/router/routes.vue")
- }])))
- routes.forEach(filteredRoute => router.addRoute(filteredRoute as RouteRecordRaw))
- app_ready.value = true
- app_routes.value = (routes as RouteRecordDetailRaw[])
- router.beforeEach((to, from) => {
- console.groupCollapsed(`%c${from.name?.toString()} => ${to.name?.toString()}`, 'color:#0ff');
- console.log(`%c${from.meta.title} => ${to.meta.title}`, 'color:#0cc');
- console.groupEnd();
- })
|