快速开始

基本开发环境需要 Node.js22 以上版本

安装方式-1 (推荐)

直接使用 npx create-antd-layout@latest your-project 安装,它提供许多已定制好的模版,方便快捷。

安装方式-2

集成到已有项目中

1. 添加 @adminui-dev/antd-layout 到项目中

npm i @adminui-dev/antd-layout
pnpm i @adminui-dev/antd-layout
yarn add @adminui-dev/antd-layout
bun add @adminui-dev/antd-layout
复制成功

2. 添加相关依赖项

package.json
"dependencies": {
    "@adminui-dev/antd-layout": "^1.8.8",
    "@ant-design/colors": "^7.2.1",
    "nprogress": "^0.2.0",
    "antd": "^6.1.1",
    "react": "^19.2.0",
    "react-dom": "^19.2.0",
    "react-intl": "^8.0.4",
    "react-router": "^7.11.0",
    "react-router-dom": "^7.11.0"
}
复制成功

3. 配置全局路由

// src/App.tsx

import { Suspense } from 'react';
import { PageLoading } from '@adminui-dev/antd-layout';
import 'nprogress/nprogress.css';
import { RouterProvider } from 'react-router';
import { routers } from './routes';

function App() {  
  return (
    <>
      <Suspense fallback={<PageLoading />}>
        <RouterProvider router={routers} />
      </Suspense>
    </>
  )
}

export default App
// src/routes.ts

import { LazyPage } from "@adminui-dev/antd-layout"
import { createBrowserRouter,redirect } from "react-router-dom"

const DashboardLayout = LazyPage(()=>import("@/layouts"))
const LoginPage = LazyPage(()=>import("@/pages/login"))
const ConfigPage = LazyPage(()=>import("@/pages/system/config"))
const LogsPage = LazyPage(()=>import("@/pages/system/logs"))
const OrderPage = LazyPage(()=>import("@/pages/transaction/order"))
const ProductPage = LazyPage(()=>import("@/pages/transaction/product"))
const WelcomePage = LazyPage(()=>import("@/pages/welcome"))

const routers = createBrowserRouter(
    [
       {path:"/",Component:DashboardLayout, children:[
        {index:true,loader:()=>redirect("/welcome")},
        {path:"welcome",Component:WelcomePage},
        {path:"system",children:[
            {index:true,loader:()=>redirect("/system/config")},
            {path:"config",Component:ConfigPage},
            {path:"logs",Component:LogsPage}
        ]},
        {path:"transaction",children:[
            {index:true,loader:()=>redirect("/transaction/order")},
            {path:"order",Component:OrderPage},
            {path:"product",Component:ProductPage}
        ]}
       ]},
       { path:"/login",Component:LoginPage }
    ]
)
export { routers }
复制成功

4. 在布局文件中使用并配置组件

// src/layout/index.tsx

import { AntdLayout } from "@adminui-dev/antd-layout"
import menuData from "./menuData";

export default function(){     
    // layout config
    const layoutConfig:LayoutConfig = {
        disabledLocale:true,
        largeBrand:true,    
        brandInfo:{
            logo:"/vite.svg",
            name:"Vite.dev",
            title:"Build tool for the web"
        },
        userInfo:{
            uid:"warden.vip",
            title:"[email protected]",
            avatar:"https://api.dicebear.com/9.x/miniavs/svg?seed=8"
        }
    } 
    return(
        <>
            <AntdLayout layoutConfig={layoutConfig} menuData={menuData} />
        </>
    )
}
// src/layout/menuData.tsx

import type { MenuData }  from "@adminui-dev/antd-layout";
import { DashboardOutlined, SmileOutlined,BlockOutlined,CarryOutOutlined,ProductOutlined,DesktopOutlined,CodeOutlined,SettingOutlined } from "@ant-design/icons";

const menuData:MenuData = {
    name:"",
    path:"/",
    label:"Dashboard",
    icon:<DashboardOutlined />,
    children:[
        {name:"welcome",path:"welcome",label:"Welcome",icon:<SmileOutlined />},
        {name:"transaction",path:"transaction",label:"Transaction",icon:<BlockOutlined />,children:[
            {name:"order",path:"order",label:"Order",icon:<CarryOutOutlined />},
            {name:"product",path:"product",label:"Product",icon:<ProductOutlined />},
        ]},
        {name:"system",path:"system",label:"System",icon:<DesktopOutlined />,children:[
            {name:"config",path:"config",label:"Config",icon:<SettingOutlined />},
            {name:"logs",path:"logs",label:"Logs",icon:<CodeOutlined />},
        ]},
    ]
}

export default menuData
复制成功

前提条件:需要node、ant-desing、react、react-dom环境