-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
routes.ts
99 lines (90 loc) · 2.68 KB
/
routes.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import type { RouteLocationNormalized, RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import type { TransitionGroupProps } from 'vue'
import type { ClicksContext, SlideInfo } from '@slidev/types'
// @ts-expect-error missing types
import _rawRoutes, { redirects } from '/@slidev/routes'
// @ts-expect-error missing types
import _configs from '/@slidev/configs'
export const rawRoutes = _rawRoutes as RouteRecordRaw[]
export const routes: RouteRecordRaw[] = [
{
name: 'play',
path: '/',
component: () => import('./internals/Play.vue'),
children: [
...rawRoutes,
...redirects,
],
},
{ name: 'print', path: '/print', component: () => import('./internals/Print.vue') },
{ path: '', redirect: { path: '/1' } },
{ path: '/:pathMatch(.*)', redirect: { path: '/1' } },
]
if (__SLIDEV_FEATURE_PRESENTER__) {
function passwordGuard(to: RouteLocationNormalized) {
if (!_configs.remote || _configs.remote === to.query.password)
return true
if (_configs.remote && to.query.password === undefined) {
// eslint-disable-next-line no-alert
const password = prompt('Enter password')
if (_configs.remote === password)
return true
}
if (to.params.no)
return { path: `/${to.params.no}` }
return { path: '' }
}
routes.push({ path: '/presenter/print', component: () => import('./internals/PresenterPrint.vue') })
if (__SLIDEV_HAS_SERVER__) {
routes.push({
name: 'entry',
path: '/entry',
component: () => import('./internals/EntrySelect.vue'),
})
routes.push({
name: 'notes',
path: '/notes',
component: () => import('./internals/NotesView.vue'),
beforeEnter: passwordGuard,
})
}
routes.push({
name: 'presenter',
path: '/presenter/:no',
component: () => import('./internals/Presenter.vue'),
beforeEnter: passwordGuard,
})
routes.push({
path: '/presenter',
redirect: { path: '/presenter/1' },
})
}
export const router = createRouter({
history: __SLIDEV_HASH_ROUTE__
? createWebHashHistory(import.meta.env.BASE_URL)
: createWebHistory(import.meta.env.BASE_URL),
routes,
})
declare module 'vue-router' {
interface RouteMeta {
// inherited from frontmatter
layout: string
name?: string
class?: string
clicks?: number
transition?: string | TransitionGroupProps | undefined
preload?: boolean
// slide info
slide?: Omit<SlideInfo, 'source'> & {
noteHTML: string
filepath: string
start: number
id: number
no: number
}
// private fields
__clicksContext: null | ClicksContext
__preloaded?: boolean
}
}