Before you ask a question, please check the following FAQ.
Ant Design Pro is developed upon Umi, please seach in Umi FAQ first.
It can be understood that Ant Design React is a set of React component libraries, and Pro is a complete front-end scaffolding using this set of component libraries.
Please read the document Getting Started, and Ant Financial users please read Getting Started (Ants Financial User).
Of course you can! Ant Design Pro is based on the latest antd version. There are currently multiple middle and backend projects in use.
antd
version separately for updating the base components.git pull https://github.com/ant-design/ant-design-pro
(note that you need to resolve conflicts yourself).Just update menuData
in models/menu, which is a json array. Just the server returns a json of similar format.
You need to update menuDataRender
prop in src/layouts/BasicLayout.tsx as below, fetch menuData from your service.
const [menuData, setMenuData] = useState([]);useEffect(() => {// just for sample// please use dva dispatch or umi-request in real worldfetch('/api/example.json').then(response => response.json()).then(data => {setMenuData(data || []);});}, []);...return (<ProLayout...menuDataRender={() => menuData}.../>);
The above menuData definite is MenuDataItem.
[{path: '/dashboard',name: 'dashboard',icon: 'dashboard',children: [{path: '/dashboard/analysis',name: 'analysis',exact: true,},{path: '/dashboard/monitor',name: 'monitor',exact: true,},{path: '/dashboard/workplace',name: 'workplace',exact: true,},],}....]
Note that path must be defined in config.ts. (All you need in Conventional Routing is the correct page.)
Sometimes you may not want to use config/config.ts
. Then you can consider umi's Conventional Routing.
Specific how to use convention routing in pro, you can see this commit.
Note: Conventional routing is easier to control menus and privileges, but requires that all menus must declare privileges, otherwise they can be accessed through direct access to urls.
Conventional permission declarations are interesting. You can declare that all pages except one page need admin access to filter all urls.
You can use umi-serve,Install umi-serve in the project or globally.
$ yarn global add umi-serveor$ yarn add umi-serve -D
Run umi-serve in the project root directory
$ umi-serveโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโ Serving your umi project! โโ โโ - Local: http://localhost:8001 โโ - On Your Network: http://134.160.170.40:8001 โโ โโ Copied local address to clipboard! โโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Modify the request address in the project,such as http://localhost:8001/api/users
[{key: '1',name: 'John Brown',age: 32,address: 'New York No. 1 Lake Park',},{key: '2',name: 'Jim Green',age: 42,address: 'London No. 1 Lake Park',},{key: '3',name: 'Joe Black',age: 32,address: 'Sidney No. 1 Lake Park',},];
Note: If there is no global installation, but only in the project, add the umi-server command to the script of package.json.
Note: Proxy is not valid after build. Do not configure request
http://localhost:8001/api/users
in proxy,when http requests, access the address directly.For example, add a request prefix uniformly insrc/utils/request.ts
.
Configurable routing,remove Routes: ['src/pages/Authorized']
configurations in config/config.ts
.
{path: '/',component: '../layouts/BasicLayout',- Routes: ['src/pages/Authorized'],routes: []...}
Details can be seen PR3842.
Conventional routing, turn off the routing permission plugin.
See roadhog configuration for details.
See details roadhog extraBabelPlugins.
Absolute paths can be used directly (map support is required). If you want to use local files directly, you can import them as follows.
<img src={require('../assets/picture.png')} />
#
character in my url? How do I get rid of?Please refer to the deploy document Routing and server integration.
Ant Design Pro has built-in umi, umi uses webpack devServer to support the proxy. You only need to configure the proxy property in config.js.As long as the proxy and mock url are different, they can be used at the same time.
{...proxy:{'/server/api/': {target: 'https://preview.pro.ant.design/',changeOrigin: true,pathRewrite: { '^/server': '' }, // /server/api/currentUser -> /api/currentUser},},...}
Enter http://localhost:8000/server/api/currentUser preview in your browser.
Open the sass
configuration in .webpackrc
, see sass.
Scaffolding defaults to the eslint code style check. Please follow the prompts and resubmit it, or you can manually check npm run lint
.
npm start
?Modify scripts.start
in package.json
to:
"start": "cross-env BROWSER=none roadhog server",
This is one of the features of Ant Design Pro. The first version is currently available in Chinese. Internationalization is in our 2.0 plan and will be released soon.
Try using tyarn or setting environment variables to see this issue.
English Documentation will be translated in next couple of monthes, trace ant-design/ant-design-pro#54 and ant-design-pro/issues/120 for more detail.
Add disableRedirectHoist: true
in config.ts configuration:
export default {...+ disableRedirectHoist: true,...}
่ฟๆฏไฝฟ็จ umijs ๆกๆถๅผๅ ฅ็้ฎ้ขใ้ ็ฝฎ็ๅ ทไฝ่ฏดๆๅ่ umijs ็ๅฎๆนๆๆกฃ่ฏดๆ
More FAQs can be found in Trouble Shooting. If this does not solve your problem, please Report to us.
Pro uses context to manage the dynamic switching of the language, which can achieve the effect of no refresh switching language, but some components are better optimized, the context modification does not re-render the component, or the component context like Portal does not exist, so it can't Switch. We can configure the way to reload the page for full re-rendering.
Import { setLocale } from 'umi-plugin-react/locale';// Set the second parameter to true to force a refreshsetLocale(key, false);