umijs / plugin-access

Umi plugin for access management.
MIT License
33 stars 3 forks source link

umi 使用 access 配置路由不生效 #14

Open sunbingye opened 3 years ago

sunbingye commented 3 years ago

//access.js 文件 export default function (initialState) { console.log('initialState', initialState); return { canReadGoods: initialState.roleId === 1 || initialState.roleId === 2 }; } // .umirc.ts 文件 routes: [ { path: '/', component: '@/layouts/index', routes: [ { path: '/', component: '@/pages/index', exact: true }, { path: '/login', component: '@/pages/login', exact: true }, { path: '/goods', component: '@/pages/goods', // exact: true, access: 'canReadGoods', }, ] } ] 已经验证 access 文件返回的 canReadGoods 值是正确的,但是 goods 路径访问没有受到影响。 还有一个问题,如果使用约定式路由,需要对 Goods 路由扩展,即在 goods.js 文件中使用 Goods.access=useAccess().canReadGoods 来进行扩展,但是 hooks 不能在函数组件外部使用,那么该如何配置?

wind4gis commented 2 months ago

同问这个问题解决了吗

sunbingye commented 2 months ago

您好,我是孙冰冶。我已经收到您的邮件,谢谢。