配置

在config.js中配置的路由是不能直接用的,参考下边的删减

  1. const [menuData, setMenuData] = useState([
  2. // {
  3. // path: '/user',
  4. // component: '../layouts/UserLayout',
  5. // routes: [
  6. // {
  7. // name: 'login',
  8. // path: '/user/login',
  9. // component: './user/login',
  10. // },
  11. // ],
  12. // },
  13. // {
  14. // path: '/',
  15. // component: '../layouts/SecurityLayout',
  16. // routes: [
  17. // {
  18. // path: '/',
  19. // component: '../layouts/BasicLayout',
  20. // authority: ['admin', 'user'],
  21. // routes: [
  22. {
  23. path: '/',
  24. redirect: '/welcome',
  25. },
  26. /* 测试 */
  27. {
  28. path: '/welcome',
  29. name: 'welcome',
  30. icon: 'home',
  31. component: './welcome/Workplace',
  32. authority: ['admin'],
  33. },
  34. {
  35. path: '/gift',
  36. name: 'giftSystem',
  37. icon: 'gift',
  38. routes: [
  39. /* 测试 */
  40. // {
  41. // name: 'giftCreate',
  42. // path: '/gift/create',
  43. // component: './giftSystem/giftCreate',
  44. // hideInMenu: true,
  45. // },
  46. {
  47. name: 'giftList',
  48. path: '/gift/list',
  49. component: './giftSystem/giftList',
  50. },
  51. ],
  52. },
  53. {
  54. path: '/active',
  55. name: 'activeSystem',
  56. icon: 'rocket',
  57. routes: [
  58. {
  59. name: 'selectActive',
  60. path: '/active/select-active',
  61. component: './activeSystem/selectActive',
  62. },
  63. {
  64. name: 'createActive',
  65. path: '/active/create',
  66. component: './activeSystem/createActive',
  67. hideInMenu: true,
  68. },
  69. {
  70. name: 'activeManage',
  71. path: '/active/manage',
  72. component: './activeSystem/activeManage',
  73. },
  74. {
  75. path: '/active/qrcode',
  76. name: 'activeQrcode',
  77. },
  78. {
  79. name: 'activeSetting',
  80. path: '/active/setting',
  81. component: './activeSystem/activeSetting',
  82. },
  83. ],
  84. },
  85. {
  86. path: '/promote',
  87. icon: 'like',
  88. name: 'promote',
  89. routes: [
  90. {
  91. name: 'trafficShop',
  92. path: '/promote/promote',
  93. component: './promote/trafficShop',
  94. },
  95. {
  96. name: 'flowToPath',
  97. path: '/promote/flow-to-path',
  98. component: './promote/flowToPath',
  99. },
  100. {
  101. name: 'myMaterial',
  102. path: '/promote/my-material',
  103. component: './promote/myMaterial',
  104. },
  105. {
  106. name: 'addTask',
  107. path: '/promote/add-task',
  108. component: './promote/addTask',
  109. },
  110. {
  111. name: 'manage',
  112. path: '/promote/manage',
  113. component: './promote/manage',
  114. },
  115. ],
  116. },
  117. {
  118. path: '/channel',
  119. icon: 'reconciliation',
  120. name: 'channel',
  121. routes: [
  122. {
  123. name: 'channelList',
  124. path: '/channel/list',
  125. component: './channel/channelList',
  126. },
  127. {
  128. name: 'crossRegionRecord',
  129. path: '/channel/cross-region',
  130. component: './channel/crossRegionRecord',
  131. },
  132. {
  133. name: 'settingField',
  134. path: '/channel/setting-field',
  135. component: './channel/settingField',
  136. },
  137. ],
  138. },
  139. {
  140. name: 'customer',
  141. icon: 'smile',
  142. path: '/customer',
  143. routes: [
  144. {
  145. path: '/customer/list',
  146. name: 'list',
  147. component: './customer',
  148. },
  149. ],
  150. },
  151. {
  152. path: '/order',
  153. name: 'order',
  154. icon: 'reconciliation',
  155. routes: [
  156. {
  157. name: 'awardRecord',
  158. path: '/order/record',
  159. component: './order/awardRecord',
  160. },
  161. {
  162. name: 'orderSetting',
  163. path: '/order/setting',
  164. component: './order/orderSetting',
  165. },
  166. ],
  167. },
  168. {
  169. path: '/dataCenter',
  170. name: 'dataCenter',
  171. icon: 'bar-chart',
  172. routes: [
  173. {
  174. name: 'summary',
  175. path: '/dataCenter/summary',
  176. component: './dataCenter/summary',
  177. },
  178. {
  179. name: 'cashPrize',
  180. path: '/dataCenter/cash-a-prize',
  181. component: './dataCenter/cashPrize',
  182. },
  183. ],
  184. },
  185. {
  186. path: '/admin',
  187. name: 'admin',
  188. icon: 'crown',
  189. component: './Admin',
  190. authority: ['admin'],
  191. },
  192. {
  193. path: '/setting',
  194. icon: 'setting',
  195. name: 'setting',
  196. routes: [
  197. {
  198. path: '/setting/account',
  199. icon: 'crown',
  200. name: 'settingAccount',
  201. component: './setting/account',
  202. },
  203. {
  204. name: 'security',
  205. icon: 'smile',
  206. path: '/setting/security',
  207. component: './setting/security',
  208. },
  209. {
  210. name: 'wechatSubscription',
  211. icon: 'smile',
  212. path: '/setting/subscription',
  213. component: './setting/wechatSubscription',
  214. },
  215. ],
  216. },
  217. {
  218. path: '/agentSystem',
  219. icon: 'crown',
  220. name: 'agentSystem',
  221. routes: [
  222. {
  223. name: 'agentList',
  224. path: '/agentSystem/agentList',
  225. component: './agentSystem/agentList',
  226. },
  227. {
  228. name: 'createAgent',
  229. path: '/agentSystem/create',
  230. component: './agentSystem/createAgent',
  231. },
  232. {
  233. name: 'agentDetail',
  234. path: '/agentsystem/agentlist/detail',
  235. component: './agentSystem/agentList/agentDetail', // hideInMenu: true,
  236. // TODO 需要在菜单中隐藏
  237. // hideInMenu: true,
  238. },
  239. {
  240. name: 'agentAudit',
  241. path: '/agentSystem/agentAudit',
  242. component: './agentSystem/agentAudit',
  243. },
  244. ],
  245. },
  246. {
  247. path: '/enterpriseManage',
  248. icon: 'database',
  249. name: 'enterpriseManage',
  250. routes: [
  251. {
  252. name: 'enterpriseList',
  253. path: '/enterprisemanage/enterpriselist',
  254. component: './enterpriseManage/enterpriseList',
  255. },
  256. {
  257. name: 'applicationList',
  258. path: '/enterprisemanage/applicationlist',
  259. component: './enterpriseManage/applicationList',
  260. },
  261. ],
  262. },
  263. {
  264. component: './404',
  265. },
  266. // ],
  267. // },
  268. {
  269. component: './404',
  270. },
  271. // ],
  272. // },
  273. {
  274. component: './404',
  275. },
  276. ])

ProLayout中的配置

  // menuDataRender={menuDataRender}
       menuDataRender={() => menuDataRender(menuData)}
  // menuDataRender={() => menuData}

如果不采用中间的方式,服务端的权限控制是没用的,需要再走一遍menuDataRender里边的检查权限方法

调教好的demo

https://github.com/withwz/test-antdesignpro-server-menu

参考

https://prolayout.ant.design/menu#%E4%BB%8E%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%8A%A0%E8%BD%BD-menu