2024-03-08 17:59:45 +08:00
|
|
|
import type { CustomRoute, ElegantConstRoute, ElegantRoute } from '@elegant-router/types';
|
|
|
|
import { generatedRoutes } from '../elegant/routes';
|
|
|
|
import { layouts, views } from '../elegant/imports';
|
2024-03-26 11:47:11 +08:00
|
|
|
import { transformElegantRoutesToVueRoutes } from '../elegant/transform';
|
2024-03-08 17:59:45 +08:00
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
/**
|
|
|
|
* custom routes
|
|
|
|
*
|
|
|
|
* @link https://github.com/soybeanjs/elegant-router?tab=readme-ov-file#custom-route
|
|
|
|
*/
|
2024-03-08 17:59:45 +08:00
|
|
|
const customRoutes: CustomRoute[] = [
|
|
|
|
{
|
|
|
|
name: 'exception',
|
|
|
|
path: '/exception',
|
|
|
|
component: 'layout.base',
|
|
|
|
meta: {
|
|
|
|
title: 'exception',
|
|
|
|
i18nKey: 'route.exception',
|
|
|
|
icon: 'ant-design:exception-outlined',
|
|
|
|
order: 7
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
name: 'exception_403',
|
|
|
|
path: '/exception/403',
|
|
|
|
component: 'view.403',
|
|
|
|
meta: {
|
|
|
|
title: 'exception_403',
|
|
|
|
i18nKey: 'route.exception_403',
|
|
|
|
icon: 'ic:baseline-block'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'exception_404',
|
|
|
|
path: '/exception/404',
|
|
|
|
component: 'view.404',
|
|
|
|
meta: {
|
|
|
|
title: 'exception_404',
|
|
|
|
i18nKey: 'route.exception_404',
|
|
|
|
icon: 'ic:baseline-web-asset-off'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'exception_500',
|
|
|
|
path: '/exception/500',
|
|
|
|
component: 'view.500',
|
|
|
|
meta: {
|
|
|
|
title: 'exception_500',
|
|
|
|
i18nKey: 'route.exception_500',
|
|
|
|
icon: 'ic:baseline-wifi-off'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
/** create routes when the auth route mode is static */
|
|
|
|
export function createStaticRoutes() {
|
2024-03-08 17:59:45 +08:00
|
|
|
const constantRoutes: ElegantRoute[] = [];
|
|
|
|
|
|
|
|
const authRoutes: ElegantRoute[] = [];
|
|
|
|
|
|
|
|
[...customRoutes, ...generatedRoutes].forEach(item => {
|
|
|
|
if (item.meta?.constant) {
|
|
|
|
constantRoutes.push(item);
|
|
|
|
} else {
|
|
|
|
authRoutes.push(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2024-03-26 11:47:11 +08:00
|
|
|
constantRoutes,
|
2024-03-08 17:59:45 +08:00
|
|
|
authRoutes
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get auth vue routes
|
|
|
|
*
|
|
|
|
* @param routes Elegant routes
|
|
|
|
*/
|
|
|
|
export function getAuthVueRoutes(routes: ElegantConstRoute[]) {
|
|
|
|
return transformElegantRoutesToVueRoutes(routes, layouts, views);
|
|
|
|
}
|