|
| 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 | + if (__SLIDEV_FEATURE_PRESENTER__) { |
| 9 | + function passwordGuard(to: RouteLocationNormalized) { |
| 10 | + if (!configs.remote || configs.remote === to.query.password) |
| 11 | + return true |
| 12 | + if (configs.remote && to.query.password === undefined) { |
| 13 | + // eslint-disable-next-line no-alert |
| 14 | + const password = prompt('Enter password') |
| 15 | + if (configs.remote === password) |
| 16 | + return true |
| 17 | + } |
| 18 | + if (to.params.no) |
| 19 | + return { path: `/${to.params.no}` } |
| 20 | + return { path: '' } |
| 21 | + } |
| 22 | + |
| 23 | + routes.push( |
| 24 | + { |
| 25 | + name: 'entry', |
| 26 | + path: '/entry', |
| 27 | + component: () => import('../pages/entry.vue'), |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'overview', |
| 31 | + path: '/overview', |
| 32 | + component: () => import('../pages/overview.vue'), |
| 33 | + }, |
| 34 | + { |
| 35 | + name: 'notes', |
| 36 | + path: '/notes', |
| 37 | + component: () => import('../pages/notes.vue'), |
| 38 | + beforeEnter: passwordGuard, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'presenter', |
| 42 | + path: '/presenter/:no', |
| 43 | + component: () => import('../pages/presenter.vue'), |
| 44 | + beforeEnter: passwordGuard, |
| 45 | + }, |
| 46 | + { |
| 47 | + path: '/presenter', |
| 48 | + redirect: { path: '/presenter/1' }, |
| 49 | + }, |
| 50 | + ) |
| 51 | + } |
| 52 | + |
| 53 | + if (__SLIDEV_HAS_SERVER__) { |
| 54 | + routes.push( |
| 55 | + { |
| 56 | + name: 'print', |
| 57 | + path: '/print', |
| 58 | + component: () => import('../pages/print.vue'), |
| 59 | + }, |
| 60 | + { |
| 61 | + path: '/presenter/print', |
| 62 | + component: () => import('../pages/presenter/print.vue'), |
| 63 | + }, |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + routes.push( |
| 68 | + { |
| 69 | + name: 'play', |
| 70 | + path: '/:no', |
| 71 | + component: () => import('../pages/play.vue'), |
| 72 | + }, |
| 73 | + { |
| 74 | + path: '', |
| 75 | + redirect: { path: '/1' }, |
| 76 | + }, |
| 77 | + ) |
| 78 | + |
| 79 | + return setups.reduce((routes, setup) => setup(routes), routes) |
| 80 | +} |
0 commit comments