echoes/frontend/core/route.ts
lsy b689233e91 后端:新增主题配置获取接口。
前端:配置了默认环境变量值,创建自定义路由,将契约和服务合并到核心
2024-11-27 01:02:05 +08:00

39 lines
914 B
TypeScript

import { ReactNode } from "react"; // Import React
import { LoaderFunction } from "react-router-dom";
interface RouteElement {
element: ReactNode,
loader?: LoaderFunction,
children?: RouteElement[],
}
export class RouteManager {
private static instance: RouteManager;
private routes = new Map<string, RouteElement>();
private routesCache = new Map<string, string>();
private constructor() { }
public static getInstance(): RouteManager {
if (!RouteManager.instance) {
RouteManager.instance = new RouteManager();
}
return RouteManager.instance;
}
private createRouteElement(
path: string,
element: RouteElement
) {
this.routes.set(path, element);
}
private getRoutes(path: string): RouteElement | undefined {
return this.routes.get(path);
}
private getRoutesCache(path: string): string | undefined {
return this.routesCache.get(path);
}
}