-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (61 loc) · 2.44 KB
/
index.js
File metadata and controls
68 lines (61 loc) · 2.44 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
56
57
58
59
60
61
62
63
64
65
66
67
68
import {createRouter, createWebHistory} from 'vue-router';
import Home from '@/views/Home.vue';
import Video from '@/views/Video.vue';
import VideoDetail from '@/views/VideoDetail.vue';
import Live from '@/views/Live.vue';
import Parser from '@/views/Parser.vue';
import Collection from '@/views/Collection.vue';
import History from '@/views/History.vue';
import Settings from '@/views/Settings.vue';
import BookGallery from '@/views/BookGallery.vue';
import ActionTest from '@/views/ActionTest.vue';
import ActionDebugTest from '@/views/ActionDebugTest.vue';
import VideoTest from '@/views/VideoTest.vue';
import CSPTest from '@/views/CSPTest.vue';
const routes = [
{path: '/', component: Home, name: 'Home'},
{path: '/video', component: Video, name: 'Video'},
{path: '/video/:id', component: VideoDetail, name: 'VideoDetail', props: true},
{path: '/live', component: Live, name: 'Live'},
{path: '/settings', component: Settings, name: 'Settings'},
{path: '/collection', component: Collection, name: 'Collection'},
{path: '/book-gallery', component: BookGallery, name: 'BookGallery'},
{path: '/history', component: History, name: 'History'},
{path: '/parser', component: Parser, name: 'Parser'},
{path: '/action-test', component: ActionTest, name: 'ActionTest'},
{path: '/action-debug-test', component: ActionDebugTest, name: 'ActionDebugTest'},
{path: '/video-test', component: VideoTest, name: 'VideoTest'},
{path: '/csp-test', component: CSPTest, name: 'CSPTest'},
// 404 fallback路由 - 必须放在最后
{path: '/:pathMatch(.*)*', redirect: '/'}
];
// 获取base路径,支持子目录部署
const getBasePath = () => {
// 在生产环境中,如果设置了VITE_BASE_PATH环境变量,使用它
if (import.meta.env.PROD && import.meta.env.VITE_BASE_PATH) {
return import.meta.env.VITE_BASE_PATH;
}
// 否则使用Vite的BASE_URL
return import.meta.env.BASE_URL;
};
const router = createRouter({
history: createWebHistory(getBasePath()),
routes,
// 滚动行为
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else {
return { top: 0 };
}
}
});
// 路由守卫 - 可以在这里添加权限检查等逻辑
router.beforeEach((to, from, next) => {
// 设置页面标题
if (to.name) {
document.title = `DrPlayer - ${to.name}`;
}
next();
});
export default router;