kun-galgame-vue/src/router/router.ts

121 lines
2.5 KiB
TypeScript
Raw Normal View History

import { type RouteRecordRaw } from 'vue-router'
export const constantRoutes: RouteRecordRaw[] = [
// KUNGalgame 登录
{
name: 'Login',
path: '/login',
component: () => import('@/views/login/Login.vue'),
meta: {
title: '登录',
},
},
// KUNGalgame 联系我们
{
name: 'Contact',
path: '/contact',
component: () => import('@/views/contact/Contact.vue'),
meta: {
title: '联系我们',
},
},
// KUNGalgame 捐助我们
{
name: 'Donate',
path: '/donate',
component: () => import('@/views/donate/Donate.vue'),
meta: {
2023-08-05 05:24:26 +00:00
title: '赞助我们',
},
},
// KUNGalgame 用户协议
{
2023-09-24 08:02:18 +00:00
name: 'Agreement',
path: '/agreement',
component: () => import('@/views/agreement/Agreement.vue'),
meta: {
title: '用户协议',
},
},
// KUNGalgame 隐私政策
{
name: 'Privacy',
path: '/privacy',
component: () => import('@/views/privacy/Privacy.vue'),
meta: {
title: '隐私政策',
},
},
// KUNGalgame 重定向页面
{
name: 'Redirect',
path: '/redirect',
redirect: '/',
component: () => import('@/views/redirect/Redirect.vue'),
meta: {
title: '重定向',
},
children: [], // 添加一个空的 children 数组redirect 配置项必须有 children
},
// KUNGalgame 404
{
name: '404',
path: '/:path(.*)*',
component: () => import('@/views/404/404.vue'),
meta: {
title: '404',
},
},
// KUNGalgame 403 TODO:
{
name: '403',
2023-10-10 12:12:01 +00:00
path: '/kungalgame403',
component: () => import('@/views/403/403.vue'),
meta: {
title: '403',
},
},
]
const isArray = (val: any): val is object =>
toString.call(val) === '[object Array]'
// 获取动态路由表
const getAsyncRoute = (): RouteRecordRaw[] => {
const modules = import.meta.glob('./modules/*.ts', {
eager: true,
import: 'default',
})
const asyncRoute: RouteRecordRaw[] = []
Object.values(modules).forEach((value) => {
const moduleList = isArray(value)
? [...(value as RouteRecordRaw[])]
: [value as RouteRecordRaw]
asyncRoute.push(...moduleList)
})
return asyncRoute
}
const getRouteName = (routeList: RouteRecordRaw[]) => {
const routeArr: string[] = []
routeList.forEach((item) => {
routeArr.push(item.name as string)
if (item?.children) {
routeArr.push(...getRouteName(item?.children))
}
})
return routeArr
}
// 异步路由
export const asyncRoutes = getAsyncRoute()
// 路由白名单
export const WHITE_LIST = getRouteName(constantRoutes)