Files
Jog/jog-frontend/src/router/index.js
T
nojava 4488c24601 feat: 导航体验优化 — 控制台入口提升 + AppLayout 返回前台链接
BlogLayout 导航菜单新增"控制台"按钮(登录后可见,普通用户→控制台,管理员→管理后台),
移除下拉菜单中冗余的控制台项。AppLayout 侧边栏新增"返回首页"和"AI 助手"入口。
路由调整:根路径指向 AI 助手,/blog 指向博客首页。

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-05-24 21:23:09 +08:00

135 lines
3.8 KiB
JavaScript

import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/login',
name: 'Login',
component: () => import('@/views/Login.vue'),
meta: { title: '登录' },
},
{
path: '/register',
name: 'Register',
component: () => import('@/views/Register.vue'),
meta: { title: '注册' },
},
{
path: '/',
component: () => import('@/layouts/BlogLayout.vue'),
children: [
{
path: '',
name: 'AiAssistant',
component: () => import('@/views/AiAssistant.vue'),
meta: { title: 'AI 助手' },
},
{
path: 'article/:id',
name: 'ArticleDetail',
component: () => import('@/views/ArticleDetail.vue'),
meta: { title: '文章详情' },
},
{
path: 'blog',
name: 'Blog',
component: () => import('@/views/Home.vue'),
meta: { title: '博客' },
},
],
},
{
path: '/app',
component: () => import('@/layouts/AppLayout.vue'),
meta: { requiresAuth: true },
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/app/Dashboard.vue'),
meta: { title: '控制台', requiresAuth: true },
},
{
path: 'articles',
name: 'MyArticles',
component: () => import('@/views/app/MyArticles.vue'),
meta: { title: '我的文章', requiresAuth: true },
},
{
path: 'editor',
name: 'NewArticle',
component: () => import('@/views/app/ArticleEditor.vue'),
meta: { title: '写文章', requiresAuth: true },
},
{
path: 'editor/:id',
name: 'EditArticle',
component: () => import('@/views/app/ArticleEditor.vue'),
meta: { title: '编辑文章', requiresAuth: true },
},
],
},
{
path: '/admin',
component: () => import('@/layouts/AdminLayout.vue'),
meta: { requiresAuth: true, requiresAdmin: true },
children: [
{
path: '',
name: 'AdminDashboard',
component: () => import('@/views/admin/Dashboard.vue'),
meta: { title: '管理后台', requiresAuth: true, requiresAdmin: true },
},
{
path: 'users',
name: 'AdminUsers',
component: () => import('@/views/admin/Users.vue'),
meta: { title: '用户管理', requiresAuth: true, requiresAdmin: true },
},
{
path: 'articles',
name: 'AdminArticles',
component: () => import('@/views/admin/Articles.vue'),
meta: { title: '文章管理', requiresAuth: true, requiresAdmin: true },
},
{
path: 'comments',
name: 'AdminComments',
component: () => import('@/views/admin/Comments.vue'),
meta: { title: '评论管理', requiresAuth: true, requiresAdmin: true },
},
{
path: 'categories',
name: 'AdminCategories',
component: () => import('@/views/admin/Categories.vue'),
meta: { title: '分类管理', requiresAuth: true, requiresAdmin: true },
},
{
path: 'ai-models',
name: 'AdminAiModels',
component: () => import('@/views/admin/AiModels.vue'),
meta: { title: 'AI 模型', requiresAuth: true, requiresAdmin: true },
},
],
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to, from, next) => {
document.title = to.meta.title ? `${to.meta.title} - 博客系统` : '博客系统'
const token = localStorage.getItem('access_token')
const userInfo = JSON.parse(localStorage.getItem('user_info') || 'null')
if (to.meta.requiresAuth && !token) {
next({ name: 'Login', query: { redirect: to.fullPath } })
} else if (to.meta.requiresAdmin && userInfo?.role !== 'ADMIN') {
next({ name: 'Blog' })
} else {
next()
}
})
export default router