73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router';
|
|
import { ensureSession } from './composables/auth';
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
{ path: '/login', name: 'login', component: () => import('./views/LoginView.vue'), meta: { public: true } },
|
|
{
|
|
path: '/',
|
|
component: () => import('./components/AppLayout.vue'),
|
|
children: [
|
|
{ path: '', name: 'overview', component: () => import('./views/OverviewView.vue'), meta: { title: '概览' } },
|
|
{
|
|
path: 'webhooks',
|
|
name: 'hooks',
|
|
component: () => import('./views/HookListView.vue'),
|
|
meta: { title: '接口管理' },
|
|
},
|
|
{
|
|
path: 'webhooks/new',
|
|
name: 'hook-new',
|
|
component: () => import('./views/HookDetailView.vue'),
|
|
meta: { title: '新建接口', nav: 'hooks' },
|
|
},
|
|
{
|
|
path: 'webhooks/:id(\\d+)',
|
|
name: 'hook-detail',
|
|
component: () => import('./views/HookDetailView.vue'),
|
|
meta: { title: '接口详情', nav: 'hooks' },
|
|
},
|
|
{
|
|
path: 'executions',
|
|
name: 'executions',
|
|
component: () => import('./views/ExecutionListView.vue'),
|
|
meta: { title: '执行记录' },
|
|
},
|
|
{
|
|
path: 'executions/:id(\\d+)',
|
|
name: 'execution-detail',
|
|
component: () => import('./views/ExecutionDetailView.vue'),
|
|
meta: { title: '执行详情', nav: 'executions' },
|
|
},
|
|
{
|
|
path: 'settings',
|
|
name: 'settings',
|
|
component: () => import('./views/SettingsView.vue'),
|
|
meta: { title: '系统设置' },
|
|
},
|
|
{
|
|
path: 'account',
|
|
name: 'account',
|
|
component: () => import('./views/AccountView.vue'),
|
|
meta: { title: '账户设置' },
|
|
},
|
|
],
|
|
},
|
|
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
|
],
|
|
});
|
|
|
|
router.beforeEach(async (to) => {
|
|
if (to.meta.public) return true;
|
|
if (await ensureSession()) return true;
|
|
return { name: 'login', query: to.fullPath !== '/' ? { redirect: to.fullPath } : {} };
|
|
});
|
|
|
|
router.afterEach((to) => {
|
|
const title = to.meta.title as string | undefined;
|
|
document.title = title ? `${title} · HookPilot` : 'HookPilot';
|
|
});
|
|
|
|
export default router;
|