The configuration is turned on.
In order to further reduce the cost of research and development, we tried to build the layout through the umi plug-in. You can have Ant Design's Layout through simple configuration, including navigation and sidebar. So that users do not need to care about the layout.
Want a dynamic menu? Check here Advanced usage of menu
You can configure the theme of layout
through the configuration file, in config/config.ts
write like this:
Import {defineConfig} from'umi';Export const config = defineConfig({layout:{//Support anything that does not require dom// https://procomponents.ant.design/components/layout#prolayoutName: "Ant Design",Region: correct,Layout: "side",},});
string
name
in package.jsonProduct name, default package name.
string
Product mark
string
pro
The specified layout theme, choose between pro
and tech
(tech
is only reflected in Ant's internal framework Bigfish).
With this switch, the plugin will search for menu in the locales file. [key]
The corresponding copywriting, replace and change the key. This function needs to be configured to use @umijs/plugin-locale
.
config supports all non-dom configurations and transmits them transparently to @ant-design/pro-layout
.
string
name
in package.jsonProduct name, the default value is the package name.
string
Product Logo
string
pro
Specify Layout theme, optional pro
and tech
(tech
only takes effect in Ant's internal framework Bigfish).
boolean
false
Whether to start international configuration. After opening, the menu name configured in the route will be used as the key for the internationalization of the menu name. The plug-in will search the locales file for the corresponding copy of menu.[key]
, and the default value is to change the key. This function needs to be configured with @umijs/plugin-locale
.
It is not possible to use dom during construction, so some configurations may need to be configured at runtime. We can do the following configuration in [src/app.tsx
](export const layout = ({):
import React from 'react';import {BasicLayoutProps,Settings as LayoutSettings,} from '@ant-design/pro-layout';export const layout = ({initialState,}: {initialState: { settings?: LayoutSettings; currentUser?: API.CurrentUser };}): BasicLayoutProps => {return {rightContentRender: () => <RightContent />,footerRender: () => <Footer />,onPageChange: () => {const { currentUser } = initialState;const { location } = history;// If you are not logged in, redirect to loginif (!currentUser && location.pathname !== '/user/login') {history.push('/user/login');}},menuHeaderRender: undefined,...initialState?.settings,};};
The runtime configuration is very flexible, but the corresponding performance may be relatively poor. In addition to the unique configuration supported by the following plugins, the runtime configuration supports all build-time configurations and transparently transmits them to @ant-design/pro-layout
.
() => void
null
In the UI that is used to configure the default Layout at runtime, the processing logic of clicking to log out will not be processed by default.
Note: By default, the exit button will not be displayed on the top right side. You need to cooperate with the
getInitialState
of@umijs/plugin-intial-state
in the running configuration to return an object before it can be displayed
(initialState) => React.ReactNode
InitialState
is obtained from the @umijs/plugin-initial-state
plugin and needs to be used together.
(error: Error, info: any) => void;
Callback after an error occurs (some error logs can be reported, management, etc.).
(error: Error) => React.ReactElement<any>;
The component displayed after the error occurred.
The Layout plugin will encapsulate more configuration items based on umi's routing, and support more configuration capabilities. Added:
Add the following configuration items:
Examples are as follows:
//config/route.tsexport const routes: IBestAFSRoute[] = [{path: '/welcome',component: 'IndexPage',name: 'Welcome', // compatible with this writingicon: 'testicon',// more features view// https://beta-pro.ant.design/docs/advanced-menu// ---// open path in new tabtarget: '_blank',// Do not show top barheaderRender: false,// Do not show footerfooterRender: false,// Do not show the menumenuRender: false,// Do not show the menu top barmenuHeaderRender: false,// Permission configuration, need to be used in conjunction with plugin-accessaccess: 'canRead',// hide child nodeshideChildrenInMenu: true,// hide yourself and child nodeshideInMenu: true,// hide in breadcrumbshideInBreadcrumb: true,// The child item is raised up and still displayed,flatMenu: true,},];
string
The name displayed on the menu, otherwise it will not be displayed.
string
The Icon displayed on the menu.
The icon name is the lower case of the component name and then remove the
outlined
orfilled
ortwotone
to obtain the value. Example: The icon name of<UserOutlined />
is:user
.
boolean
The default is false. Only this item is hidden in the menu, and the sub-items are raised up and still displayed.false
string
It takes effect when the Layout plugin is used in conjunction with the @umijs/plugin-access
plugin.
The permission plugin will match the access string configured by the user here with all the permissions of the current user. If the same item is found and the value of the permission is false, the 403 page will be displayed by default when the user accesses the route.
-Type: string
The internationalization configuration of the menu, the internationalization key is menu.${submenu-name}.${name}
.
-Type: string
The antd icon, in order to load the layout plug-in on demand, will automatically convert it to the dom of the Antd icon. Support types can be found in antd (https://ant.design/components/icon-cn/).
-Type: boolean
Flatten the menu. If you only want the child menu to not show yourself, you can configure it to true
const before = [{ name: '111' }, { name: '222', children: [{ name: '333' }] }];// flatMenu = trueconst after = [{ name: '111' }, { name: '222' }, { name: '333' }];
-Type: boolean
If xxxRender is set to false, some layout modules will not be displayed
headerRender=false
does not show the top barfooterRender=false
does not show footermenuRender=false
does not show the menumenuHeaderRender=false
does not display the title and logo of the menu-Type: boolean
hideInXXX can manage the rendering of the menu.
hideChildrenInMenu=true
to hide the child menuhideInMenu=true
hide yourself and submenushideInBreadcrumb=true
hide in breadcrumbs