获取匹配的路由matchPath数组
menus: [
{
name: '支用详情',
path: '/workplat/task-detail/disburse-apply-approve/disburse-detail',
matchPath: '/workplat/task-detail/disburse-apply-approve/disburse-detail',
},
{
name: '授信详情1',
path: '/workplat/task-detail/disburse-apply-approve/shouxin1',
matchPath: '/workplat/task-detail/disburse-apply-approve/shouxin1',
},
{
name: '授信详情2',
path: '/workplat/task-detail/disburse-apply-approve/shouxin2',
matchPath: '/workplat/task-detail/disburse-apply-approve/shouxin2',
},
],
matchSelectedMenu = () => {
const { menus } = this.state;
const paths = window.location.pathname.split('/');
const matchs = menus.filter(menu => {
const matchPaths = menu.matchPath.split('/');
for (let i = 0; i < paths.length; i += 1) {
if (matchPaths[i] !== '*' && matchPaths[i] !== paths[i]) {
return false;
}
}
return true;
});
console.log('matchSelectedMenu', paths, matchs);
this.setState({
selectedKeys: matchs.map(v => v.matchPath),
});
};