arco-design / arco-design-pro

An out-of-the-box solution to quickly build enterprise-level applications based on Arco Design.
https://pro.arco.design
MIT License
485 stars 95 forks source link

权限控制菜单,在初次渲染中,会渲染默认路由中所有的菜单(有权限/无权限) #79

Open windofme1314 opened 2 years ago

windofme1314 commented 2 years ago
image

Basic Info

What is expected?

不应该出现没有权限的菜单

Steps to reproduce

  1. 在 arco-design-pro-next 下的 src/routes.ts 中的 useRoute 函数中打一个断点
  2. 在 src/routes.ts 中修改 routes 数组: export const routes: IRoute[] = [ { name: 'menu.dashboard', key: 'dashboard', children: [ { name: 'menu.dashboard.workplace', key: 'dashboard/workplace', }, { name: 'menu.dashboard.monitor', key: 'dashboard/monitor', requiredPermissions: [ { resource: 'menu.dashboard.monitor', actions: ['write']}, ], }, ], }]
  3. 页面中切换用户,将角色由管理员修改为普通用户
  4. 刷新页面,左侧菜单中出现了所有的菜单项(没有权限的菜单项也被渲染了)
windofme1314 commented 2 years ago

useRoute 由于内部依赖了 useEffect,会在页面渲染完以后再次更新内部的 permissionRoute 状态,导致页面多渲染一次