Files
hldrCenter/management/src/router/index.ts

80 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-10-03 22:30:54 +08:00
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')
2025-10-04 16:14:54 +08:00
const NewsView = () => import('../views/news/NewsView.vue')
2025-10-03 22:30:54 +08:00
// 定义路由规则(现在 RouteRecordRaw 导入正确)
const routes: RouteRecordRaw[] = [
{
2025-10-04 16:14:54 +08:00
path: '/home',
2025-10-03 22:30:54 +08:00
name: 'Home',
component: HomeView,
meta: {
title: '首页',
requiresAuth: false
}
},
2025-10-04 16:14:54 +08:00
{
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
}
},
2025-10-03 22:30:54 +08:00
{
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