it-tools/src/router.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-31 00:33:29 +02:00
import { createRouter, createWebHistory } from 'vue-router';
2022-08-04 22:46:50 +02:00
import { layouts } from './layouts/index';
2022-03-31 00:33:29 +02:00
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';
import { config } from './config';
import { routes as demoRoutes } from './ui/demo/demo.routes';
2022-03-31 00:33:29 +02:00
2022-04-22 23:31:40 +02:00
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)
2022-04-22 23:31:40 +02:00
.flatMap(
({ path, redirectFrom }) => redirectFrom?.map((redirectSource) => ({ path: redirectSource, redirect: path })) ?? [],
);
2022-03-31 00:33:29 +02:00
const router = createRouter({
history: createWebHistory(config.app.baseUrl),
2022-03-31 00:33:29 +02:00
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,
...(config.app.env === 'development' ? demoRoutes : []),
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;