消毒机设备
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.

29 lines
698 B

3 weeks ago
3 weeks ago
3 weeks ago
  1. import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
  2. import { getToken } from '@/libs/token'
  3. import { createWebSocket } from 'libs/socket'
  4. import { createRouter, createWebHashHistory } from 'vue-router'
  5. import routes from './routes'
  6. const wsClient = createWebSocket()
  7. const router = createRouter({
  8. history: createWebHashHistory(),
  9. routes,
  10. })
  11. router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
  12. if (getToken() && wsClient.isConnected) {
  13. next()
  14. }
  15. else {
  16. // 未登录
  17. if (to.name === 'login') {
  18. next()
  19. }
  20. else {
  21. next({ name: 'login' })
  22. }
  23. }
  24. })
  25. export default router