mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-05-06 18:29:24 +08:00
30 lines
781 B
TypeScript
30 lines
781 B
TypeScript
|
|
|
|
|
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
import ChatPage from '../views/ChatPage.vue';
|
|
import LoginPage from '../views/LoginPage.vue';
|
|
|
|
const routes = [
|
|
{ path: '/', redirect: '/chat' },
|
|
{ path: '/login', component: LoginPage },
|
|
{ path: '/chat', component: ChatPage }, // 聊天页面
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
});
|
|
|
|
// 路由守卫,确保用户登录后才能访问聊天页面
|
|
router.beforeEach((to, from, next) => {
|
|
const isAuthenticated = document.cookie.includes('auth_token'); // 假设后端返回的是这个Cookie
|
|
if (to.path === '/chat' && !isAuthenticated) {
|
|
next('/login'); // 未登录时跳转到登录页面
|
|
} else {
|
|
next(); // 允许进入
|
|
}
|
|
});
|
|
|
|
export default router;
|