当首页没有权限不跳进404页面, 跳进接口菜单list返回的第一个

接口数据

  {
    path: '/systemc',
    redirect: '/system/userc',
    name: 'Systemc',
    meta: {
      title: '管理后台...',
      icon: 'c...'
    },
    children: [
      {
        path: 'user..'
      },
    ]
  }

      //当首页没有权限 不跳进404页面, 跳进接口菜单list返回的第一个

    let index = -1
    let diffUrl = ''
    let endPath = ''
    const endMap = (list) => {
      for (const key in list) {
        if (Object.prototype.hasOwnProperty.call(list, key)) {
          const item = list[key]
          if (item.path === diffUrl) {
            endPath = endPath + diffUrl
            console.log(endPath, 'endPath', diffUrl, 'diffUrl')
        //跳转 push({ path: endPath
|| diffUrl }) return } else if (diffUrl.includes(item.path)) { endPath = item.path + '/' + item.children[0]?.path console.log(endPath, 'endPath', diffUrl, 'diffUrl')
push({ path: endPath
|| diffUrl }) return } else { if (item.children?.length) { endPath = item.path + '/' + endPath endMap(item.children) } else { // endPath = '' } } } } } const redirectFn = (isHomeObj) => { if (isHomeObj) { if (接口数据.find((item) => item.path === isHomeObj.path)) { diffUrl = isHomeObj.redirect || isHomeObj.path endMap(routers) return } else if ( isHomeObj.redirect && 接口数据.find((item) => isHomeObj.redirect.includes(item.path)) ) { endMap(接口数据.find((item) => isHomeObj.redirect.includes(item.path)).children) return } else { index++ if (index > 接口数据.length - 1) { return } console.log(index, 'index') 接口数据[index] && redirectFn(接口数据[index]) } } else { redirectFn(接口数据[0]) } } const isHomeObj = 接口数据.find((item) => item.path === '/home') redirectFn(isHomeObj)

 

posted @ 2025-08-04 15:42  前端张大碗  阅读(2)  评论(0)    收藏  举报