/* * @Author: fxs bjnsfxs@163.com * @Date: 2024-08-20 14:06:49 * @LastEditors: fxs bjnsfxs@163.com * @LastEditTime: 2024-10-10 17:35:00 * @FilePath: \Game-Backstage-Management-System\src\router\index.ts * @Description: * */ import { createRouter, createWebHashHistory } from 'vue-router' import { authLogin } from '@/utils/axios/auth' import HomeRoutes from './home' import LoginRoutes from './login' import AppManage from './appManage' const routes = [ ...LoginRoutes, { path: '/index', name: 'Index', redirect: '/index/home/overView', component: () => import('@/views/Index.vue'), children: [...HomeRoutes, ...AppManage] }, { path: '/', redirect: '/home/overView' }, { //访问不存在的路由的时候,跳转到首页 path: '/:pathMatch(.*)', redirect: '/home/overView' } ] const router = createRouter({ history: createWebHashHistory(), routes }) router.beforeEach((to, _from, next) => { if (to.name === 'Login') { next() } else { if (authLogin()) { next() } else { router.push('login') } } }) export default router