88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import { useAuthStore } from '../stores/auth.js'
|
|
|
|
const routes = [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('../views/Login.vue')
|
|
},
|
|
{
|
|
path: '/',
|
|
component: () => import('../views/Layout.vue'),
|
|
redirect: '/datasets',
|
|
children: [
|
|
{
|
|
path: 'datasets',
|
|
name: 'DatasetList',
|
|
meta: { title: '数据集' },
|
|
component: () => import('../views/DatasetList.vue')
|
|
},
|
|
{
|
|
path: 'datasets/:id',
|
|
name: 'DatasetDetail',
|
|
meta: { title: '数据集详情' },
|
|
component: () => import('../views/DatasetDetail.vue')
|
|
},
|
|
{
|
|
path: 'chat',
|
|
name: 'Chat',
|
|
meta: { title: '问答' },
|
|
component: () => import('../views/Chat.vue')
|
|
},
|
|
{
|
|
path: 'kg',
|
|
name: 'KgGraph',
|
|
meta: { title: '知识图谱' },
|
|
component: () => import('../views/KgGraph.vue')
|
|
},
|
|
{
|
|
path: 'reference-cases',
|
|
name: 'ReferenceCase',
|
|
meta: { title: '参考案例库' },
|
|
component: () => import('../views/ReferenceCase.vue')
|
|
},
|
|
{
|
|
path: 'cases',
|
|
name: 'CaseList',
|
|
meta: { title: '我的案件' },
|
|
component: () => import('../views/CaseList.vue')
|
|
},
|
|
{
|
|
path: 'cases/:id',
|
|
name: 'CaseDetail',
|
|
meta: { title: '案件详情' },
|
|
component: () => import('../views/CaseDetail.vue')
|
|
},
|
|
{
|
|
path: 'settings',
|
|
name: 'Settings',
|
|
meta: { title: '设置' },
|
|
component: () => import('../views/Settings.vue')
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
// hash 路由:前后端合并部署后 SPA 路由与后端 API 前缀重叠,
|
|
// history 模式刷新会命中 API 路由;hash 模式页面始终请求 /,由后端静态服务返回 index.html
|
|
history: createWebHashHistory(),
|
|
routes
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const auth = useAuthStore()
|
|
if (to.path !== '/login' && !auth.isLoggedIn) {
|
|
next('/login')
|
|
return
|
|
}
|
|
if (to.path === '/login' && auth.isLoggedIn) {
|
|
next('/')
|
|
return
|
|
}
|
|
next()
|
|
})
|
|
|
|
export default router
|