feat: 网络请求+发布订阅模块
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
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'
|
||||
|
||||
@@ -13,4 +15,11 @@ const router = createRouter({
|
||||
// 创建路由守卫
|
||||
createRouterGuard(router)
|
||||
|
||||
/** 订阅 401 未授权事件:清除 token 并跳转登录页 */
|
||||
eventBus.on(AppEvents.UNAUTHORIZED, () => {
|
||||
const accountStore = useAccountStore()
|
||||
accountStore.token = ''
|
||||
router.push('/auth/login')
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user