feat: add-tool network (#9)

Co-authored-by: typist <git@mail.typist.cc>
Reviewed-on: #9
This commit is contained in:
2025-10-29 05:51:11 +08:00
parent b97c746d36
commit 3b31ce9ddf
12 changed files with 1318 additions and 48 deletions

View File

@@ -2,11 +2,30 @@ import {
createBrowserRouter,
redirect,
RouterProvider,
type RouteObject,
} from "react-router-dom";
import { tools } from "@/components/tool";
import { tools, type Tool } from "@/components/tool";
import { Layout } from "./layout";
const buildToolRoutes = (tools: Tool[]): RouteObject[] => {
return tools.map((tool) => {
const route: RouteObject = {
path: tool.path,
};
if (tool.component) {
route.element = tool.component;
}
if (tool.children && tool.children.length > 0) {
route.children = buildToolRoutes(tool.children);
}
return route;
});
};
// 路由配置
const router = createBrowserRouter([
{
@@ -16,19 +35,14 @@ const router = createBrowserRouter([
{
path: "tool",
children: [
...tools.map((tool) => (
{
path: tool.path,
element: tool.component,
}
)),
...buildToolRoutes(tools),
{
index: true,
loader: () => redirect("/tool/uuid"),
},
]
],
},
]
],
},
{
index: true,