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:
@@ -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>
|
||||||
tools.map((tool) => (
|
<SidebarGroupLabel>
|
||||||
<SidebarMenuItem key={tool.name}>
|
Tools
|
||||||
<SidebarMenuButton>
|
</SidebarGroupLabel>
|
||||||
{tool.icon}
|
<SidebarGroupContent>
|
||||||
{tool.name}
|
{
|
||||||
</SidebarMenuButton>
|
tools.map((tool) => (
|
||||||
</SidebarMenuItem>
|
<SidebarMenuItem key={tool.name}>
|
||||||
))
|
<SidebarMenuButton asChild>
|
||||||
}
|
<Link to={`/tool/${tool.path}`} title={tool.description}>
|
||||||
|
{tool.icon}
|
||||||
|
{tool.name}
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -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 />
|
||||||
|
|||||||
@@ -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");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user