index.ts
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-10 17:56:22
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 19:22:32
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\router\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import appsManifest from '../mfe/apps.json'
const routes: RouteRecordRaw[] = [
{
path: '/login',
name: 'Login',
component: () => import('../pages/Login.vue'),
},
{
path: '/',
component: () => import('../layout/BaseLayout.vue'),
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Home',
meta: { requiresAuth: true },
component: () => import('../pages/Home.vue'),
},
...appsManifest.apps.map((m) => ({
path: m.route,
name: `Micro_${m.dir}`,
meta: { requiresAuth: true },
component: () => import('../pages/MicroHost.vue'),
})),
],
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to, _from, next) => {
const token = localStorage.getItem('token')
if (to.path === '/login') {
if (token) return next('/')
return next()
}
if (to.meta && (to.meta as any).requiresAuth && !token) {
return next('/login')
}
next()
})
export default router