index.ts
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import Test from '@/views/Test.vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 配置NProgress
NProgress.configure({ showSpinner: false })
// 静态路由
const staticRoutes: RouteRecordRaw[] = [
{
path: '/',
name: 'Test',
component: Test,
meta: {
title: '测试页面',
requiresAuth: false
}
}
]
// 创建路由实例
const router = createRouter({
history: createWebHistory(),
routes: staticRoutes,
scrollBehavior: () => ({ top: 0 })
})
// 路由守卫
router.beforeEach(async (to, from, next) => {
// 开始进度条
NProgress.start()
// 设置页面标题
if (to.meta.title) {
document.title = `${to.meta.title} - Apple经销商ERP系统`
}
// 暂时跳过所有权限检查,直接放行
next()
})
router.afterEach(() => {
// 结束进度条
NProgress.done()
})
// 路由错误处理
router.onError((error) => {
console.error('路由错误:', error)
NProgress.done()
})
export default router