feat: enhance routing and sidebar with dynamic tools integration
- Added a new AppSidebar component to display tools in the sidebar. - Introduced a tools array in the tool module to manage tool properties. - Updated router configuration to dynamically generate routes for each tool.
This commit is contained in:
25
src/components/sidebar/index.tsx
Normal file
25
src/components/sidebar/index.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar";
|
||||||
|
import { tools } from "@/components/tool";
|
||||||
|
|
||||||
|
export const AppSidebar = () => (
|
||||||
|
<Sidebar>
|
||||||
|
<SidebarHeader>
|
||||||
|
Lite Kit
|
||||||
|
</SidebarHeader>
|
||||||
|
<SidebarContent>
|
||||||
|
{
|
||||||
|
tools.map((tool) => (
|
||||||
|
<SidebarMenuItem key={tool.name}>
|
||||||
|
<SidebarMenuButton>
|
||||||
|
{tool.icon}
|
||||||
|
{tool.name}
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</SidebarContent>
|
||||||
|
<SidebarFooter>
|
||||||
|
<a href="mailto:litek@mail.typist.cc">contact us</a>
|
||||||
|
</SidebarFooter>
|
||||||
|
</Sidebar>
|
||||||
|
)
|
||||||
8
src/components/tool/index.tsx
Normal file
8
src/components/tool/index.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
interface Tool {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
component: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const tools: Tool[] = [];
|
||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
|
|
||||||
import { Layout } from "./layout";
|
import { Layout } from "./layout";
|
||||||
|
import { tools } from "@/components/tool";
|
||||||
|
|
||||||
// 路由配置
|
// 路由配置
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
@@ -15,18 +16,20 @@ const router = createBrowserRouter([
|
|||||||
{
|
{
|
||||||
path: "tools",
|
path: "tools",
|
||||||
children: [
|
children: [
|
||||||
|
...tools.map((tool) => (
|
||||||
|
{
|
||||||
|
path: tool.name,
|
||||||
|
element: tool.component,
|
||||||
|
}
|
||||||
|
)),
|
||||||
{
|
{
|
||||||
index: true,
|
index: true,
|
||||||
loader: () => redirect(`/empty`),
|
element: null,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "empty",
|
|
||||||
element: <div>Nohting</div>,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
index: true,
|
index: true,
|
||||||
loader: () => {
|
loader: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user