2024-11-19 00:20:31 +08:00
|
|
|
import React from 'react'; // Import React
|
2024-11-20 19:53:18 +08:00
|
|
|
import { LoaderFunction, RouteObject } from 'react-router-dom';
|
2024-11-18 01:09:28 +08:00
|
|
|
|
|
|
|
export class RouteManager {
|
|
|
|
private static instance: RouteManager;
|
|
|
|
private routes: RouteObject[] = [];
|
|
|
|
|
2024-11-19 00:20:31 +08:00
|
|
|
private constructor() {}
|
2024-11-18 01:09:28 +08:00
|
|
|
|
2024-11-19 00:20:31 +08:00
|
|
|
public static getInstance(): RouteManager {
|
|
|
|
if (!RouteManager.instance) {
|
|
|
|
RouteManager.instance = new RouteManager();
|
2024-11-18 01:09:28 +08:00
|
|
|
}
|
|
|
|
return RouteManager.instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-20 19:53:18 +08:00
|
|
|
private createRouteElement(path: string,element:React.ReactNode,loader?:LoaderFunction,children?:RouteObject[]) {
|
2024-11-19 00:20:31 +08:00
|
|
|
this.routes.push({
|
|
|
|
path,
|
|
|
|
element,
|
2024-11-20 19:53:18 +08:00
|
|
|
loader,
|
|
|
|
children,
|
2024-11-19 00:20:31 +08:00
|
|
|
})
|
2024-11-18 01:09:28 +08:00
|
|
|
}
|
|
|
|
|
2024-11-20 19:53:18 +08:00
|
|
|
private getRoutes(): RouteObject[] {
|
2024-11-18 01:09:28 +08:00
|
|
|
return this.routes;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|