import type { RouteRecordRaw } from 'vue-router' ; import isUrl from './isUrl' ; export { clearMenuItem , flatMap , getMenuFirstChildren } from './index' ; export type MenuData = { menuData : RouteRecordRaw [ ] ; breadcrumb : Record < string , any > ; } ; export const formatRelativePath = ( routes , breadcrumb , parent ? ) : RouteRecordRaw [ ] => { return routes . map ( route => { if ( isUrl ( route . path ) ) { return route ; } const hasRelativePath = route . path . startsWith ( '/' ) ; if ( ! hasRelativePath ) { if ( parent ) { route . path = `${ parent . path || '' }/${ route . path }` ; } else { route . path = `/${ route . path }` ; } } route . path = route . path . replace ( '//' , '/' ) ; if ( route . children && route . children . length > 0 ) { route . children = formatRelativePath ( route . children , breadcrumb , route ) ; } breadcrumb [ `${ route . path }` ] = route ; return route ; } ) ; } ; param routes param child returns { childrens export const getMenuData = ( routes , child ? ) : MenuData => { const childrenRoute = routes . find ( route => ( child && ( child . name === route . name || child ?. path === route . path ) ) || route . path === '/' ) ; const breadcrumb = { } ; return { menuData : formatRelativePath ( childrenRoute ?. children || ( [ ] as RouteRecordRaw [ ] ) , breadcrumb , undefined ) , breadcrumb , } ; } ;