You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
865 B
33 lines
865 B
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
|
|
import { useSystemStore } from 'stores/systemStore'
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import { getToken } from '@/libs/token'
|
|
import routes from './routes'
|
|
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes,
|
|
})
|
|
|
|
router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
|
|
const systemStore = useSystemStore()
|
|
if (getToken() && (systemStore.systemStatus.currentUser?.username || import.meta.env.FT_NODE_ENV !== 'prod')) {
|
|
if (to.name === 'login') {
|
|
next({ name: from.name })
|
|
}
|
|
else {
|
|
next()
|
|
}
|
|
}
|
|
else {
|
|
// 未登录
|
|
if (to.name === 'login') {
|
|
next()
|
|
}
|
|
else {
|
|
next({ name: 'login' })
|
|
}
|
|
}
|
|
})
|
|
|
|
export default router
|