我随便输入一个路由,就匹配到403了,我想知道有什么办法

我的router.config代码是这样的
// App 根目录
{
path: '/',
context: 'space',
component: '../layouts/BasicLayout',
Routes: ['src/pages/Authorized'],
authority: ['admin', 'super_admin'],
routes: [
{
path: '/',
redirect: '/location/manage',
},
{
name: 'location',
icon: 'location',
path: '/location',
routes: [
{
path: 'manage',
name: '分店管理',
component: './Locations/LocationsManage',
},
{
path: 'add',
name: '添加分店',
component: './Locations/AddLocationForm',
},
],
},
{
name: '个人设置',
path: '/user-setting',
component: './User/UserSettingForm',
hideInMenu: true,
},
{
name: '员工',
icon: 'member',
path: '/members',
...
},
{
component: './Members/MemberInfo',
name: 'MENU.MEMBERS.MEMBER_INFO',
path: '/members/info',
hideInMenu: true,
routes: [
{
component: './Members/MemberDeskForm',
name: 'MENU.MEMBERS.MEMBER_ENTER',
path: 'desk',
hideInMenu: true
}
]
},
{
name: '公司设置',
path: 'settings',
icon: 'spaceSettings',
component: './SpaceSetting/SpaceInfo'
},
{
name: 'MENU.SPACE_SETTINGS.LOCK_SETTING',
path: 'locks-settings',
component: './SpaceSetting/SpaceLocksSettings',
hideInMenu: true
},
{
name: 'exception',
icon: 'warning',
path: '/exception',
hideInMenu: true,
routes: [
// exception
{
path: '/exception/403',
name: 'not-permission',
component: './Exception/403',
},
{
path: '/exception/404',
name: 'not-find',
component: './Exception/404',
},
{
path: '/exception/500',
name: 'server-error',
component: './Exception/500',
},
{
path: '/exception/trigger',
name: 'trigger',
hideInMenu: true,
component: './Exception/TriggerException',
},
],
},
{
component: '404',
},
],
},
看不出来问题,看看是不是 400 这个组件里面就是 403。或者是在 Authorized 这个里面处理的?
还有问题的话提供个最小复现的仓库看看。
@yutingzhao1991 找到原因了,暂时没想到有什么好的办法。
当匹配到一个其他路径时
它的authority是['noAuthority'],当前currentAuthority是['admin', 'super_admin'] 所以进入了 403 Exception,

BasicLayout.js
<Authorized authority={routerConfig} noMatch={<Exception403 />}>
{children}
</Authorized>
@yutingzhao1991
有解决办法了。
我发现['noAuthority']时,其实就是找不到route的时候,因为如果check router.config 没有authority限制的组件时 返回的是undefined,所以直接return target了。
// 没有判定权限.默认查看所有
// Retirement authority, return target;
if (!authority) {
return target;
}
So update BasicLayout.js
const DEFAULT_ROUTE_AUTHORITY = ['noAuthority']
...
noMatchComponent = (routerConfig) => routerConfig === DEFAULT_ROUTE_AUTHORITY ? <Exception404 /> : <Exception403 />
...
<Authorized authority={routerConfig} noMatch={this.noMatchComponent(routerConfig)}>
{children}
</Authorized>
Most helpful comment
@yutingzhao1991
有解决办法了。
我发现['noAuthority']时,其实就是找不到route的时候,因为如果check router.config 没有authority限制的组件时 返回的是undefined,所以直接return target了。
So update BasicLayout.js