feat: enhance tool routing and add network tools

- Refactored routing logic in src/router.tsx to utilize a buildToolRoutes function for better scalability.
- Updated tools in src/components/tool/index.tsx to include a new "Network Tools" category with DNS, Ping, TCPing, and Speed Test components.
This commit is contained in:
typist
2025-10-29 05:35:37 +08:00
parent 3d80b4b2b6
commit 79c4462bfd
2 changed files with 25 additions and 10 deletions

View File

@@ -10,7 +10,8 @@ export interface Tool {
name: string; name: string;
icon: ReactNode; icon: ReactNode;
description: string; description: string;
component: ReactNode; component?: ReactNode;
children?: Tool[];
} }
export const tools: Tool[] = [ export const tools: Tool[] = [

View File

@@ -2,11 +2,30 @@ import {
createBrowserRouter, createBrowserRouter,
redirect, redirect,
RouterProvider, RouterProvider,
type RouteObject,
} from "react-router-dom"; } from "react-router-dom";
import { tools } from "@/components/tool"; import { tools, type Tool } from "@/components/tool";
import { Layout } from "./layout"; 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([ const router = createBrowserRouter([
{ {
@@ -16,19 +35,14 @@ const router = createBrowserRouter([
{ {
path: "tool", path: "tool",
children: [ children: [
...tools.map((tool) => ( ...buildToolRoutes(tools),
{
path: tool.path,
element: tool.component,
}
)),
{ {
index: true, index: true,
loader: () => redirect("/tool/uuid"), loader: () => redirect("/tool/uuid"),
}, },
] ],
}, },
] ],
}, },
{ {
index: true, index: true,