mirror of
https://gitee.com/mirrors/AllinSSL.git
synced 2026-03-12 09:40:10 +08:00
【同步】前端项目源码
【修复】工作流兼容问题
This commit is contained in:
31
frontend/apps/allin-ssl/src/router/each.tsx
Normal file
31
frontend/apps/allin-ssl/src/router/each.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createDiscreteApi } from 'naive-ui'
|
||||
|
||||
import type { Router, RouteLocationNormalized, NavigationGuardNext } from '@baota/router/each'
|
||||
import { useCreateRouterEach } from '@baota/router/each' // 全局路由守卫
|
||||
|
||||
// 创建离散API
|
||||
const { loadingBar } = createDiscreteApi(['loadingBar'])
|
||||
|
||||
/**
|
||||
* @description 全局路由守卫
|
||||
* @param {Router} router 路由实例
|
||||
* @return {void}
|
||||
*/
|
||||
const useRouterEach = (router: Router) =>
|
||||
useCreateRouterEach(router, {
|
||||
beforeEach: (to: RouteLocationNormalized, _: RouteLocationNormalized, next: NavigationGuardNext) => {
|
||||
// 开始加载
|
||||
loadingBar.start()
|
||||
// 判断当前路由是否存在,如果不存在,则跳转到 404
|
||||
if (!router.hasRoute(to.name as string)) {
|
||||
if (!to.path.includes('/404')) return next({ path: '/404' })
|
||||
}
|
||||
next()
|
||||
},
|
||||
afterEach: (to: RouteLocationNormalized) => {
|
||||
loadingBar.finish()
|
||||
console.log('afterEach', to)
|
||||
},
|
||||
})
|
||||
|
||||
export default useRouterEach
|
||||
17
frontend/apps/allin-ssl/src/router/import.tsx
Normal file
17
frontend/apps/allin-ssl/src/router/import.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getBuildRoutes } from '@baota/router/import'
|
||||
import routeConfig from '@config/route'
|
||||
|
||||
/**
|
||||
* @description 创建路由,动态获取路由配置
|
||||
* @returns {RouteRecordRaw[]} 路由配置
|
||||
*/
|
||||
export const createRoutes = () => {
|
||||
const modules = import.meta.glob('../views/*/index.tsx')
|
||||
const childrenModules = import.meta.glob(`../views/*/children/*/index.tsx`)
|
||||
return getBuildRoutes(modules, childrenModules, {
|
||||
framework: routeConfig.frameworkRoute,
|
||||
system: routeConfig.systemRoute,
|
||||
sort: routeConfig.sortRoute,
|
||||
disabled: routeConfig.disabledRoute,
|
||||
})
|
||||
}
|
||||
17
frontend/apps/allin-ssl/src/router/index.tsx
Normal file
17
frontend/apps/allin-ssl/src/router/index.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { createWebHistory, useCreateRouter } from '@baota/router' // 框架路由
|
||||
import { createRoutes } from './import' // 自动导入路由配置
|
||||
import useRouterEach from './each' // 全局路由守卫
|
||||
|
||||
// 获取路由
|
||||
const { routeGroup, routes } = createRoutes() // 获取路由配置
|
||||
|
||||
// 创建路由
|
||||
const router = useCreateRouter({
|
||||
routes: routeGroup,
|
||||
history: createWebHistory(),
|
||||
})
|
||||
|
||||
// 全局路由守卫
|
||||
useRouterEach(router)
|
||||
|
||||
export { router, routes }
|
||||
Reference in New Issue
Block a user