Replies: 11 comments
-
|
坐等大佬升到V5 |
Beta Was this translation helpful? Give feedback.
-
|
坐等大佬发出代码 |
Beta Was this translation helpful? Give feedback.
-
|
坐等大佬发出代码 |
Beta Was this translation helpful? Give feedback.
-
|
占个位置 |
Beta Was this translation helpful? Give feedback.
-
|
~~来了来了,让大家久等了 ^_^ 1 我的router.js 2 后端返回的路由格式 3 BasicLayout.jsx 代码 5 主要逻辑 1 要区分菜单与路由的区别 菜单 在ant design pro v4.5 只有两个属性 path 和 name 就可以确定菜单了 比如把以下数组传给proLayout组件的 route 属性就可以在侧边展示一个发布报表的菜单了,最多再加一个icon,则展示相应icon 路由 信息 在ant design pro v4.5 只有两个属性 path 和 component 就可以确定相应path(路由)对应的component了, 最多再添加一个redirect属性 因此现在要做的事情就是用户登录成功后获取后端动态路由(菜单)信息,然后把 相应的 path 和name给到proLayout渲染出菜单,再把相应的path和component对应信息动态挂载到BasicLayout组件的props.route.routes上,即暴力修改这个routes就可以了,当然要注意一点,这样的话刷新浏览器对应的path不会加载到对应的component了,需要以下bug fix // fix bug: 刷新浏览器对应的path不会加载component 另外我这个动态菜单不是在BasicLayout.jsx中dispatch请求的,而是把请求过的数据直接指定给ProLayout的route属性,这样个人感觉好一些,比较简洁,并且不用要多写个loading 来fix 渲染menu的问题 |
Beta Was this translation helpful? Give feedback.
-
|
你的做法与 #4691 不同,原文通过在路由中不配置path并缓存 compoents,最后根据接口信息 unShift 路由信息。
@dealdot |
Beta Was this translation helpful? Give feedback.
-
|
格式化一下代码吧 |
Beta Was this translation helpful? Give feedback.
-
|
安装你的代码实现了,路由权限管理,现在有个问题就是不知道为啥子菜单的icon不显示,大佬你的正常吗 |
Beta Was this translation helpful? Give feedback.
-
|
动态路由的意义何在 |
Beta Was this translation helpful? Give feedback.
-
and design 默认就不让显示子菜单icon |
Beta Was this translation helpful? Give feedback.
-
|
应用后,path: '/warning/event/:id',以及hideInMenu之类的不能正常使用 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
🧐 ant design pro v4 实现路由,菜单完全由后端返回,不在router.js中配置
估计大家有跟我一样从Vue转过来React使用 ant design pro v4 想实现动态路由,动态菜单的,即不在router.js中配置需要动态变化的路由和菜单信息, 由于ant design的封装比较厉害,实现起来不像Vue那样简单直接,看了很多issue, 结合自己的思路实现了一版,由于这一版的ant design pro V4 支持 patchRoutes,主要就是利用这一点,但我绕开了这个函数,暴力修改routes, 参考了
[#4691] (#4691) @liangyongrui
© 版本信息
"name": "ant-design-pro",
"version": "4.5.0",
"umi": "^3.2.14",
浏览器环境 chrome
开发环境 windows10
💻 示例代码,稍后贴上 BasicLayout.jsx 代码,代码已贴出,见评论区
Beta Was this translation helpful? Give feedback.
All reactions