初始化
This commit is contained in:
42
management/src/router/index.ts
Normal file
42
management/src/router/index.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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')
|
||||
|
||||
// 定义路由规则(现在 RouteRecordRaw 导入正确)
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
component: HomeView,
|
||||
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
|
||||
Reference in New Issue
Block a user