60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import type { ElegantConstRoute, ElegantRoute, CustomRoute } from '@elegant-router/types';
|
|
import { generatedRoutes } from '../elegant/routes';
|
|
import { layouts, views } from '../elegant/imports';
|
|
import { transformElegantRoutesToVueRoutes } from '../elegant/transform';
|
|
|
|
export const ROOT_ROUTE: CustomRoute = {
|
|
name: 'root',
|
|
path: '/',
|
|
redirect: '/home',
|
|
meta: {
|
|
title: 'root',
|
|
constant: true
|
|
}
|
|
};
|
|
|
|
const customRoutes: CustomRoute[] = [
|
|
ROOT_ROUTE,
|
|
{
|
|
name: 'not-found',
|
|
path: '/:pathMatch(.*)*',
|
|
component: 'layout.blank$view.404',
|
|
meta: {
|
|
title: 'not-found',
|
|
constant: true
|
|
}
|
|
}
|
|
];
|
|
|
|
/**
|
|
* create routes
|
|
*/
|
|
export function createRoutes() {
|
|
const constantRoutes: ElegantRoute[] = [];
|
|
|
|
const authRoutes: ElegantRoute[] = [];
|
|
|
|
[...customRoutes, ...generatedRoutes].forEach(item => {
|
|
if (item.meta?.constant) {
|
|
constantRoutes.push(item);
|
|
} else {
|
|
authRoutes.push(item);
|
|
}
|
|
});
|
|
|
|
const constantVueRoutes = transformElegantRoutesToVueRoutes(constantRoutes, layouts, views);
|
|
|
|
return {
|
|
constantVueRoutes,
|
|
authRoutes
|
|
};
|
|
}
|
|
|
|
/**
|
|
* get auth vue routes
|
|
* @param routes elegant routes
|
|
*/
|
|
export function getAuthVueRoutes(routes: ElegantConstRoute[]) {
|
|
return transformElegantRoutesToVueRoutes(routes, layouts, views);
|
|
}
|