Files
JARVIS/frontend/src/router/index.ts

22 lines
495 B
TypeScript
Raw Normal View History

2026-03-21 10:13:35 +08:00
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { routes } from '@/app/router/routes'
2026-03-21 10:13:35 +08:00
const router = createRouter({
history: createWebHistory(),
routes,
2026-03-21 10:13:35 +08:00
})
router.beforeEach((to, _from, next) => {
const auth = useAuthStore()
if (to.meta.requiresAuth && !auth.isAuthenticated) {
next('/login')
} else if (to.meta.guest && auth.isAuthenticated) {
next('/chat')
} else {
next()
}
})
export default router