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.
 
 
 

52 lines
1.3 KiB

import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '../stores/auth';
const routes = [
{
path: '/',
redirect: 'homePage'
},
{
path: '/homePage',
name: 'homePage',
component: () => import('../views/homePage.vue'),
// children: [
// {name: 'AiEmotion', path: '/AiEmotion', component: () => import('@/views/AiEmotion.vue')}
// ]
},
{
path: '/choujiang',
name: 'choujiang',
component: () => import('../views/choujiang/index.vue'),
},
{
path: '/zhongchou',
name: 'zhongchou',
component: () => import('../views/zhongchou/index.vue'),
},
{
path: '/login',
name: 'login',
component: () => import('../views/choujiang/Login.vue'),
}
]
// 创建路由实例
const router = createRouter({
history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
routes
})
// 添加路由守卫
router.beforeEach((to, from, next) => {
const authStore = useAuthStore(); // 获取auth store实例
// 仅对/choujiang路由进行登录验证
if (to.path === '/choujiang') {
if (!authStore.isLoggedIn) {
// 如果未登录,重定向到登录页面
next('/login');
return;
}
}
next();
})
// 导出
export default router