Files
WebTools/src/router.ts
T

35 lines
941 B
TypeScript

import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import { toolById, toolComponents, tools } from '@/tools/registry'
const toolRoutes: RouteRecordRaw[] = tools.map((tool) => ({
path: `/tools/${tool.id}`,
name: tool.id,
component: toolComponents[tool.id],
meta: {
title: tool.title,
categoryId: tool.category,
toolId: tool.id,
},
}))
export const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', redirect: '/tools/utf8-hex' },
...toolRoutes,
{
path: '/tools/setting',
name: 'setting',
component: () => import('@/views/SettingView.vue'),
meta: { title: '工具管理' },
},
{ path: '/:pathMatch(.*)*', redirect: '/tools/utf8-hex' },
],
scrollBehavior: () => ({ top: 0 }),
})
router.beforeEach((to) => {
if (to.meta.toolId && !toolById.has(String(to.meta.toolId))) return '/tools/utf8-hex'
return true
})