Files
aida_front/src/router/index.ts
X1627315083 10e5d35498 取消测试
2024-03-04 16:48:06 +08:00

120 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createRouter, createWebHistory, RouteRecordRaw, createWebHashHistory } from 'vue-router'
import { defineAsyncComponent } from 'vue'
import { getBrowserInfo, murmur } from '@/tool/util'
import { getCookie, setCookie } from "@/tool/cookie";
const _import = (path: string) => defineAsyncComponent(() => import(`../views/${path}.vue`));
const routes: Array<RouteRecordRaw> = [
{
path: "/",
// redirect重定向
redirect: "/login"
// redirect: "/upgrade"
},
{
path: '/login',
name: 'login',
component: _import('LoginPage')
},
{
path: '/upgrade',
name: 'upgrade',
component: _import('Upgrade'),
},
{
path: '/home',
name: 'home',
component: _import('HomeView')
},
{
path: '/demo',
name: 'demo',
component: _import('Demo')
},
{
path: '/history',
name: 'history',
component: _import('HistoryPage')
},
// {//老版本history
// path: '/oldHistory',
// name: 'oldHistory',
// component: _import('OldHistoryPage')
// },
{
path: '/library',
name: 'library',
component: _import('LibraryPage')
},
{
path: '/trialApproval',
name: 'trialApproval',
component: _import('trialApproval')
},
{
path: '/setIdentification',
name: 'setIdentification',
component: _import('setIdentification')
},
{
path: '/404',
name: '404',
component: _import('404')
},
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
// history: createWebHashHistory(),
routes
})
router.beforeEach((to, from, next) => {
// 系统维护
// const toName = to.name === 'upgrade';
// if (toName) {
// next();
// } else {
// next({ name: 'upgrade' });
// }
// 检查路由是否存在
// 机房用户
let murmurStr: any = localStorage.getItem('murmurStr')
let getIsMurmur: any = getCookie("isMurmur")
let token = getCookie("token");
let isMurmur = JSON.parse(getIsMurmur)
const routeExists = router.getRoutes().some(({ name }) =>{
if(name){
return name === to.name
}else{
return false
}
});
if (routeExists) {
if (isMurmur && murmurStr && token) {
const toName = to.name === 'login';
if (toName) {
next({ name: 'home' });
} else {
next();
}
} else {
// 如果页面存在,正常跳转
const toName = to.name === 'upgrade';
if (toName) {
next({ name: 'login' });
} else {
next();
}
}
} else {
// 如果页面不存在可以跳转到404页面或者其他页面
next('/404');
}
});
export default router