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

import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
import { getToken } from '@/libs/token'
import { createWebSocket } from 'libs/socket'
import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes'
const wsClient = createWebSocket()
const router = createRouter({
history: createWebHashHistory(),
routes,
})
router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
if (getToken() && wsClient.isConnected) {
next()
}
else {
// 未登录
if (to.name === 'login') {
next()
}
else {
next({ name: 'login' })
}
}
})
export default router