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') const CommunityView = () => import('../views/community/CommunityView.vue') const ResourceView = () => import('../views/resource/ResourceView.vue') const BaseOverview = ()=> import('../views/baseoverview/BaseOverView.vue') const DevProjectView = ()=> import('../views/devproject/devprojectView.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: ResourceView, meta: { title: '资源案例', requiresAuth: false } }, { path: '/community', name: 'Community', component: CommunityView, 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: '关于我们' } }, { path: '/baseoverview', name: 'baseoverview', component: BaseOverview, meta: { title: '编辑基地概况', requiresAuth: false } }, { path: '/devproject', name: 'devproject', component: DevProjectView, meta: { title: '编辑科学研究', requiresAuth: false } } ] 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