policeSecurity/superManagement/src/router/staticRouters.ts

55 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-08-29 17:06:00 +08:00
import {RouteRecordRaw} from "vue-router";
2024-08-30 17:03:25 +08:00
import {SYSTEM_MENUS} from "@/config";
import {SystemMenu} from "@/types/config";
/**
*
*/
const extractMenuToRouter = (): RouteRecordRaw[] => {
const result: RouteRecordRaw[] = []
const traverse = (data: SystemMenu[]) => {
data.forEach(item => {
if (item.type === 'dir' && item.children && item.children.length > 0) {
traverse(item.children)
} else {
result.push({
path: item.path,
name: item.name,
meta: {
title: item.title
},
component: item.component
} as RouteRecordRaw)
}
})
}
traverse(SYSTEM_MENUS)
return result;
}
2024-08-29 17:06:00 +08:00
export const staticRouter: RouteRecordRaw[] = [
{
path: '/login',
name: 'login',
meta: {
title: '登录',
},
component: () => import("@/views/login.vue"),
}, {
path: "/",
redirect: '/index',
}, {
path: '/layout',
name: 'layout',
redirect: '/index',
2024-08-30 17:03:25 +08:00
component: () => import("@/components/layout/Layout.vue"),
children: extractMenuToRouter()
}, {
path: '/test',
name: 'test',
component: () => import("@/views/test.vue"),
},
2024-08-29 17:06:00 +08:00
]