mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-12-16 01:03:55 +08:00
feat:完成简易的的前端和后端api
This commit is contained in:
29
frontend/src/router/index.ts
Normal file
29
frontend/src/router/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user