diff --git a/src/router/index.ts b/src/router/index.ts index a08abd8..6928d9a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,6 @@ import vuex from '@/store' -import type { MyRouteMeta, MyRouteRecordRaw } from '@/types/router' -import { createRouter, createWebHistory } from 'vue-router' +import type {MyRouteMeta, MyRouteRecordRaw} from '@/types/router' +import {createRouter, createWebHistory} from 'vue-router' import auth from './routers/auth' import user from './routers/user' @@ -53,7 +53,9 @@ router.beforeEach((to, from, next) => { const isAuthenticated: string = vuex.getters.isLogin if (to.name !== 'AuthLogin' && to.meta.requiresAuth && !isAuthenticated) { - next({ name: 'AuthLogin', query: { to: to.path } }) + next({name: 'AuthLogin', query: {to: to.path}}) + } else if (isAuthenticated && (to.name == 'AuthLogin' || to.name == 'AuthRegister')) { + next({name: 'Home'}) } else { next() } @@ -63,7 +65,7 @@ router.beforeEach((to, from, next) => { * 设置文档标题 * @param meta MyRouteMeta */ -function setDocumentTitle (meta: MyRouteMeta) { +function setDocumentTitle(meta: MyRouteMeta) { document.title = meta?.title const ua = navigator.userAgent // eslint-disable-next-line diff --git a/src/store/index.ts b/src/store/index.ts index 0136d69..bec1ff0 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -23,11 +23,11 @@ export default createStore({ tokenType: '' }, getters: { - isLogin: (state: State) => { + isLogin: (state: State): boolean => { return state.isLogin }, // 获取组合后的token - accessToken: (state: State) => { + accessToken: (state: State): string => { return state.tokenType + ' ' + state.accessToken } }, diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index 849f07a..9bccef7 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -1,16 +1,13 @@ -