Files
webgame-frontend/src/router/index.ts
2026-06-16 16:16:47 +08:00

26 lines
661 B
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import { eventBus, AppEvents } from '@/utils/eventBus'
import { useAccountStore } from '@/stores'
import { createRouterGuard } from './guard.ts'
import routes from './routes.ts'
/**
* 创建路由实例
*/
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: routes
})
// 创建路由守卫
createRouterGuard(router)
/** 订阅 401 未授权事件:清除认证状态并跳转登录页 */
eventBus.on(AppEvents.UNAUTHORIZED, () => {
const accountStore = useAccountStore()
accountStore.logout()
router.push('/auth/login')
})
export default router