antdpro设置动态路由
时间: 2023-06-28 20:07:18 浏览: 243
在 Ant Design Pro 中设置动态路由需要进行以下步骤:
1. 在 `config/config.js` 文件中配置路由,具体代码如下:
```javascript
export default {
routes: [
{
path: '/',
component: '../layouts/BasicLayout',
routes: [
{ path: '/', redirect: '/dashboard' },
{ path: '/dashboard', component: './Dashboard' },
{ path: '/about/:id', component: './About' }, // 动态路由
],
},
],
};
```
2. 在页面组件中获取动态路由参数,具体代码如下:
```javascript
import React from 'react';
import { connect } from 'dva';
const About = ({ match }) => {
const { id } = match.params; // 获取动态路由参数
return <div>About {id}</div>;
};
export default connect()(About);
```
3. 在菜单中设置动态路由,具体代码如下:
```javascript
export default {
routes: [
{
path: '/',
component: '../layouts/BasicLayout',
routes: [
{ path: '/', redirect: '/dashboard' },
{ path: '/dashboard', name: 'Dashboard', component: './Dashboard' },
{ path: '/about/:id', name: 'About', component: './About' },
],
},
],
// 菜单配置
menu: {
// 菜单项配置
items: [
{
key: 'dashboard',
name: 'Dashboard',
icon: 'dashboard',
path: '/dashboard',
},
{
key: 'about',
name: 'About',
icon: 'info-circle',
path: '/about/:id',
hideInMenu: true, // 隐藏菜单项
},
],
},
};
```
以上就是在 Ant Design Pro 中设置动态路由的步骤。
阅读全文