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:
@@ -10,7 +10,8 @@ export interface Tool {
|
||||
name: string;
|
||||
icon: ReactNode;
|
||||
description: string;
|
||||
component: ReactNode;
|
||||
component?: ReactNode;
|
||||
children?: Tool[];
|
||||
}
|
||||
|
||||
export const tools: Tool[] = [
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user