Initial release of Web Tools 0.0.5
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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/ascii-hex' },
|
||||
...toolRoutes,
|
||||
{
|
||||
path: '/setting',
|
||||
name: 'setting',
|
||||
component: () => import('@/views/SettingView.vue'),
|
||||
meta: { title: '工具管理' },
|
||||
},
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/tools/ascii-hex' },
|
||||
],
|
||||
scrollBehavior: () => ({ top: 0 }),
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
if (to.meta.toolId && !toolById.has(String(to.meta.toolId))) return '/tools/ascii-hex'
|
||||
return true
|
||||
})
|
||||
Reference in New Issue
Block a user