feat: update layout and routing for sidebar integration

- Replaced Sidebar component with AppSidebar in the layout.
- Updated routing paths from "tools" to "tool" for consistency.
- Enhanced AppSidebar to include a grouped structure for tools with links.
This commit is contained in:
typist
2025-10-28 00:29:23 +08:00
parent 0c54293312
commit 4f1e9dcde1
3 changed files with 30 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar";
import { tools } from "@/components/tool"; import { tools } from "@/components/tool";
import { Link } from "react-router-dom";
export const AppSidebar = () => ( export const AppSidebar = () => (
<Sidebar> <Sidebar>
@@ -7,16 +8,25 @@ export const AppSidebar = () => (
Lite Kit Lite Kit
</SidebarHeader> </SidebarHeader>
<SidebarContent> <SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>
Tools
</SidebarGroupLabel>
<SidebarGroupContent>
{ {
tools.map((tool) => ( tools.map((tool) => (
<SidebarMenuItem key={tool.name}> <SidebarMenuItem key={tool.name}>
<SidebarMenuButton> <SidebarMenuButton asChild>
<Link to={`/tool/${tool.path}`} title={tool.description}>
{tool.icon} {tool.icon}
{tool.name} {tool.name}
</Link>
</SidebarMenuButton> </SidebarMenuButton>
</SidebarMenuItem> </SidebarMenuItem>
)) ))
} }
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent> </SidebarContent>
<SidebarFooter> <SidebarFooter>
<a href="mailto:litek@mail.typist.cc">contact us</a> <a href="mailto:litek@mail.typist.cc">contact us</a>

View File

@@ -1,11 +1,12 @@
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"
import { Sidebar } from "@/components/ui/sidebar"
import type { FC } from "react" import type { FC } from "react"
import { Outlet } from "react-router-dom"; import { Outlet } from "react-router-dom";
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"
import { AppSidebar } from "@/components/sidebar";
export const Layout: FC = () => ( export const Layout: FC = () => (
<SidebarProvider> <SidebarProvider>
<Sidebar /> <AppSidebar />
<main> <main>
<SidebarTrigger /> <SidebarTrigger />
<Outlet /> <Outlet />

View File

@@ -4,8 +4,8 @@ import {
RouterProvider, RouterProvider,
} from "react-router-dom"; } from "react-router-dom";
import { Layout } from "./layout";
import { tools } from "@/components/tool"; import { tools } from "@/components/tool";
import { Layout } from "./layout";
// 路由配置 // 路由配置
const router = createBrowserRouter([ const router = createBrowserRouter([
@@ -14,11 +14,11 @@ const router = createBrowserRouter([
element: <Layout />, element: <Layout />,
children: [ children: [
{ {
path: "tools", path: "tool",
children: [ children: [
...tools.map((tool) => ( ...tools.map((tool) => (
{ {
path: tool.name, path: tool.path,
element: tool.component, element: tool.component,
} }
)), )),
@@ -33,13 +33,13 @@ const router = createBrowserRouter([
{ {
index: true, index: true,
loader: () => { loader: () => {
return redirect("/tools"); return redirect("/tool");
}, },
}, },
{ {
path: "*", path: "*",
loader: () => { loader: () => {
return redirect("/tools"); return redirect("/tool");
}, },
}, },
]); ]);