fix.router

This commit is contained in:
zhangdongxue
2021-09-17 21:12:11 +08:00
parent ffde8dbb92
commit d06ce894f7
3 changed files with 10 additions and 11 deletions

View File

@@ -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

View File

@@ -23,11 +23,11 @@ export default createStore<State>({
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
}
},

View File

@@ -1,16 +1,13 @@
<template>
<div class="home">
</div>
</template>
<script lang="ts" setup>
</script>
<script lang="ts">
export default {
name: 'Home'
}
</script>
<style scoped>
</style>