當(dāng)首頁(yè)沒(méi)有權(quán)限不跳進(jìn)404頁(yè)面, 跳進(jìn)接口菜單list返回的第一個(gè)
接口數(shù)據(jù)
{
path: '/systemc',
redirect: '/system/userc',
name: 'Systemc',
meta: {
title: '管理后臺(tái)...',
icon: 'c...'
},
children: [
{
path: 'user..'
},
]
}
//當(dāng)首頁(yè)沒(méi)有權(quán)限 不跳進(jìn)404頁(yè)面, 跳進(jìn)接口菜單list返回的第一個(gè)
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')
//跳轉(zhuǎn) 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 (接口數(shù)據(jù).find((item) => item.path === isHomeObj.path)) { diffUrl = isHomeObj.redirect || isHomeObj.path endMap(routers) return } else if ( isHomeObj.redirect && 接口數(shù)據(jù).find((item) => isHomeObj.redirect.includes(item.path)) ) { endMap(接口數(shù)據(jù).find((item) => isHomeObj.redirect.includes(item.path)).children) return } else { index++ if (index > 接口數(shù)據(jù).length - 1) { return } console.log(index, 'index') 接口數(shù)據(jù)[index] && redirectFn(接口數(shù)據(jù)[index]) } } else { redirectFn(接口數(shù)據(jù)[0]) } } const isHomeObj = 接口數(shù)據(jù).find((item) => item.path === '/home') redirectFn(isHomeObj)

浙公網(wǎng)安備 33010602011771號(hào)