it-tools/src/router.ts

32 lines
1 KiB
TypeScript
Raw Normal View History

2022-04-04 00:24:45 +02:00
import { layouts } from './layouts/index';
2022-03-31 00:33:29 +02:00
import { createRouter, createWebHistory } from 'vue-router';
import HomePage from './pages/Home.page.vue';
2022-04-05 17:40:35 +02:00
import NotFound from './pages/404.page.vue';
2022-03-31 00:33:29 +02:00
import { tools } from './tools';
const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({ path, name, component, meta: { isTool: true, layout: layouts.toolLayout, name, ...config } }));
const toolsRedirectRoutes = tools
.filter(({ redirectFrom }) => redirectFrom && redirectFrom.length > 0)
.flatMap(({ path, redirectFrom }) => redirectFrom?.map((redirectSource) => ({ path: redirectSource, redirect: path })) ?? []);
2022-03-31 00:33:29 +02:00
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: HomePage,
},
2022-04-16 10:46:52 +02:00
{
path: '/about',
name: 'about',
component: () => import('./pages/About.vue'),
},
...toolsRoutes,
...toolsRedirectRoutes,
2022-04-05 17:40:35 +02:00
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
2022-03-31 00:33:29 +02:00
],
});
export default router;