Files
hldrCenter/management/src/router/index.ts
2025-10-04 20:25:05 +08:00

91 lines
2.0 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
// 关键修复:使用 import type 导入类型
import type { RouteRecordRaw } from 'vue-router'
// 懒加载组件
const HomeView = () => import('../views/HomeView.vue')
const AboutView = () => import('../views/AboutView.vue')
const NewsView = () => import('../views/news/NewsView.vue')
const PublishView = () => import('../views/publish/PublishView.vue')
// 定义路由规则(现在 RouteRecordRaw 导入正确)
const routes: RouteRecordRaw[] = [
{
path: '/home',
name: 'Home',
component: HomeView,
meta: {
title: '首页',
requiresAuth: false
}
},
{
path: '/news',
name: 'News',
component: NewsView,
meta: {
title: '新闻动态',
requiresAuth: false
}
},
{
path: '/resource',
name: 'Resource',
component: HomeView,
meta: {
title: '资源案例',
requiresAuth: false
}
},
{
path: '/community',
name: 'Community',
component: HomeView,
meta: {
title: '社区服务',
requiresAuth: false
}
},
{
path: '/person',
name: 'Person',
component: HomeView,
meta: {
title: '个人中心',
requiresAuth: false
}
}
,
{
path: '/publish',
name: 'Publish',
component: PublishView,
meta: {
title: '文章发布',
requiresAuth: false
}
},
{
path: '/about',
name: 'About',
component: AboutView,
meta: {
title: '关于我们'
}
}
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes
})
// 导航守卫:自动更新页面标题
router.beforeEach((to) => {
if (to.meta.title) {
document.title = to.meta.title as string
}
})
export default router