当前位置: 首页 > Web前端 > JavaScript

显示和删除面包屑导航栏

时间:2023-03-27 01:18:47 JavaScript

BreadcrumbNameMap:菜单名文件;1、新建路由和菜单名对应的BreadcrumbNameMap.js文件,导入到frame.js文件中(控制路由跳转,即页面显示);2.将Breadcrumb3导入到frame.js文件中,获取当前页面的url(即:props.location.pathname)4.在ahooks中使用useLocalStorageState存储路由,这样面包屑仍然会显示const[choseRoutes,setChose]=useLocalStorageState('choseRoutes',()=>{return[];});5.获取所有显示页面的路由if(choseRoutes.length>0){setChose([...choseRoutes,url]);}else{setChose([url]);}6.过滤已经完成ExistingroutesconstremainRoutes=chosenRoutes.filter((item,RouteIndex,array)=>{returnarray.indexOf(item)===RouteIndex;});7.遍历路由数组,显示remainRoutes.map((i,openIndex)=>{return({BreadcrumbNameMap[i]}{if(remainRoutes.length<=1){message.info('所有页面导航不能删除');}else{//BreadcrumbNameMap[i]页面表面显示路由名称,delIndex删除remainRoutes中路由的下标delIndexconsole.log(i,url,openIndex);//i===删除路由并更新页面内容if(i===url){if(openIndex===0){props.history.push(remainRoutes[openIndex+1]);}else{props.history.push(remainRoutes[openIndex-1]);}}remainRoutes.splice(openIndex,1);//删除对应下标的urlsetChose(remainRoutes);}}}>删除);})