Antd does not have permission to jump back to page 403 when entering the menu, but this is not what we really want.

problem description

I set permissions for each menu, but after actually logging in, I find the page that jumps after landing according to the order inside the route. if the first one happens to have no permission, it will jump to the 403 page. but the reality is that I want it to jump to the first menu with permission.

the environmental background of the problems and what methods you have tried

I get the permissions of the current user in the siderMenu file, and then compare with the permissions in the menu list, and then find the first menu with permissions to load it, but there will be various problems, such as refreshing the page url address remains the same but jump to other pages, the submenu will be hidden after clicking, click on the home page will also jump to 403, refresh the page will jump to the first menu, and so on a series of questions.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

//  403
const getAuthorityArr = getAuthority().split(",");
const menuArr = this.props.menuData;
if (this.props !== nextProps) {
  let clog = "0"; // 10
  let currentPathAuthorized = []; //  path
  const getPathAuthority = (menuData, location) => {
    menuData.forEach((item) => {
      if (item.path === location.pathname) {
        currentPathAuthorized = item.authority;
      }
      if (item.children) {
        item.children.forEach((childrenItem) => {
          if (childrenItem.path === location.pathname) {
            currentPathAuthorized = childrenItem.authority;
          }
        });
      }
    })
  }
  getPathAuthority(nextProps.menuData, nextProps.location);
  for (let i = 0; i < currentPathAuthorized.length; i += 1) {
    for (let j = 0; j < nextProps.menuData.length; j += 1) {
      if (nextProps.menuData[j].authority.indexOf(currentPathAuthorized[i]) > -1) {
        clog = "1";
        break;
      }
    }
  }
  // if (clog === "1") {
    if (true) {
    this.setState({
      openKeys: this.getDefaultCollapsedSubMenus(nextProps),
    });
  } else {
    let menuPath = "";
    for (let i = 0; i < getAuthorityArr.length; i += 1) {
      for (let j = 0; j < menuArr.length; j += 1) {
        if (menuArr[j].authority.indexOf(getAuthorityArr[i]) > -1) {
          menuPath = menuArr[j].path;
          break;
        }
      }
    }
    const newProps = { ...this.props }
    newProps.location.pathname = menuPath;
    this.setState({
      openKeys: this.getDefaultCollapsedSubMenus(newProps),
    });
  }
}

what result do you expect? What is the error message actually seen?

expect that as soon as you enter the page, you will find the corresponding page according to your permissions, instead of 403.

Apr.01,2021

in fact, antd does judge permissions in srclayoutsBasicLayout.js. The reason for my problem is that permissions are added to menu, but some places in router do not add permissions, which leads to the assumption that some of my menus have open permissions, so there is a matching error. Just add permissions to router.

Menu