返回 slidev
routes.ts
根目录 / packages / client / setup / routes.ts
1 import type { RouteLocationNormalized, RouteRecordRaw } from 'vue-router'
2 import configs from '#slidev/configs'
3 import setups from '#slidev/setups/routes'
4
5 export default function setupRoutes() {
6 const routes: RouteRecordRaw[] = []
7
8 function passwordGuard(to: RouteLocationNormalized) {
9 if (!configs.remote || configs.remote === to.query.password)
10 return true
11 if (configs.remote && to.query.password === undefined) {
12 // eslint-disable-next-line no-alert
13 const password = prompt('Enter password')
14 if (configs.remote === password)
15 return true
16 }
17 if (to.params.no)
18 return { path: `/${to.params.no}` }
19 return { path: '' }
20 }
21
22 if (__SLIDEV_FEATURE_PRESENTER__) {
23 routes.push(
24 {
25 name: 'entry',
26 path: '/entry',
27 component: () => import('../pages/entry.vue'),
28 beforeEnter: passwordGuard,
29 },
30 {
31 name: 'overview',
32 path: '/overview',
33 component: () => import('../pages/overview.vue'),
34 beforeEnter: passwordGuard,
35 },
36 {
37 name: 'notes',
38 path: '/notes',
39 component: () => import('../pages/notes.vue'),
40 beforeEnter: passwordGuard,
41 },
42 {
43 name: 'notes-edit',
44 path: '/notes-edit',
45 component: () => import('../pages/notes-edit.vue'),
46 beforeEnter: passwordGuard,
47 },
48 {
49 name: 'presenter',
50 path: '/presenter/:no',
51 component: () => import('../pages/presenter.vue'),
52 beforeEnter: passwordGuard,
53 },
54 {
55 path: '/presenter',
56 redirect: { path: '/presenter/1' },
57 },
58 )
59 }
60
61 if (__SLIDEV_FEATURE_PRINT__) {
62 routes.push(
63 {
64 name: 'print',
65 path: '/print',
66 component: () => import('../pages/print.vue'),
67 beforeEnter: passwordGuard,
68 },
69 {
70 path: '/presenter/print',
71 component: () => import('../pages/presenter/print.vue'),
72 beforeEnter: passwordGuard,
73 },
74 )
75 }
76
77 if (__SLIDEV_FEATURE_BROWSER_EXPORTER__) {
78 routes.push(
79 {
80 name: 'export',
81 path: '/export/:no?',
82 component: () => import('../pages/export.vue'),
83 beforeEnter: passwordGuard,
84 },
85 )
86 }
87
88 routes.push(
89 {
90 name: 'play',
91 path: '/:no',
92 component: () => import('../pages/play.vue'),
93 },
94 {
95 path: '',
96 redirect: { path: '/1' },
97 },
98 {
99 path: '/:pathMatch(.*)*',
100 name: 'NotFound',
101 component: () => import('../pages/404.vue'),
102 },
103 )
104
105 return setups.reduce((routes, setup) => setup(routes), routes)
106 }
107
107 lines TYPESCRIPT