2026-03-21 10:13:35 +08:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
|
import { useAuthStore } from '@/stores/auth'
|
2026-03-21 22:13:12 +08:00
|
|
|
import { routes } from '@/app/router/routes'
|
2026-03-21 10:13:35 +08:00
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
2026-03-21 22:13:12 +08:00
|
|
|
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
|