feat: add basic layout (#3)
Co-authored-by: typist <git@mail.typist.cc> Reviewed-on: #3
This commit is contained in:
48
src/router.tsx
Normal file
48
src/router.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
createBrowserRouter,
|
||||
redirect,
|
||||
RouterProvider,
|
||||
} from "react-router-dom";
|
||||
|
||||
import { Layout } from "./layout";
|
||||
import { tools } from "@/components/tool";
|
||||
|
||||
// 路由配置
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "",
|
||||
element: <Layout />,
|
||||
children: [
|
||||
{
|
||||
path: "tools",
|
||||
children: [
|
||||
...tools.map((tool) => (
|
||||
{
|
||||
path: tool.name,
|
||||
element: tool.component,
|
||||
}
|
||||
)),
|
||||
{
|
||||
index: true,
|
||||
element: null,
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
index: true,
|
||||
loader: () => {
|
||||
return redirect("/tools");
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
loader: () => {
|
||||
return redirect("/tools");
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
// 路由提供者组件
|
||||
export const AppRouter = () => <RouterProvider router={router} />;
|
||||
Reference in New Issue
Block a user