import { createRouter, createWebHistory, Router, RouteRecordRaw } from 'vue-router'; import { setCurrentPath } from '/@/enum/pageEnum.ts'; import { getAuthCache } from '/@/utils/auth.ts'; import { TOKEN_KEY } from '/@/enum/cacheEnum.ts'; const routes: Array = [ { path: '/', name: 'default', redirect: '/login', }, { path: '/login', name: 'login', meta: { //西安大屏登录 title: '登录', }, component: () => import('/@/views/sys/login.vue'), }, { path: '/home2', name: 'index2', meta: { title: '副屏', }, component: () => import('/@/views/healthConsultation/HealthConsultationIndex.vue'), }, { path: '/home', name: 'index', meta: { title: '健康咨询', }, component: () => import('/@/views/indexSun.vue'), }, { path: '/indexSon', name: 'indexSon', meta: { title: '心血管监测', }, component: () => import('/@/views/indexSon.vue'), }, { path: '/home1', name: 'index1', meta: { title: '副屏1', }, component: () => import('/@/views/index.vue'), }, ]; const router: Router = createRouter({ history: createWebHistory('/'), routes: [...routes], }); router.beforeEach((to, from, next) => { if (to.path !== '/login') { setCurrentPath(to.path); } if (to.path == '/login') { next(); } else { const flag = getAuthCache('flag3'); const token = getAuthCache(TOKEN_KEY); if (!flag || !token) { return next({ path: '/login' }); } else { next(); } } }); export default router;