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

2 months ago
2 months ago
  1. import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
  2. import { useSystemStore } from 'stores/systemStore'
  3. import { createRouter, createWebHashHistory } from 'vue-router'
  4. import { getToken } from '@/libs/token'
  5. import routes from './routes'
  6. const router = createRouter({
  7. history: createWebHashHistory(),
  8. routes,
  9. })
  10. router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
  11. const systemStore = useSystemStore()
  12. if (getToken() && (systemStore.systemStatus.currentUser?.username || import.meta.env.FT_NODE_ENV !== 'prod')) {
  13. if (to.name === 'login') {
  14. next({ name: from.name })
  15. }
  16. else {
  17. next()
  18. }
  19. }
  20. else {
  21. // 未登录
  22. if (to.name === 'login') {
  23. next()
  24. }
  25. else {
  26. next({ name: 'login' })
  27. }
  28. }
  29. })
  30. export default router