import { IRouterConfig } from '../types' ; import joinPath from '../utils/joinPath' ; export default function formatRoutes ( routes , parentPath ? ) { return routes . map ( ( item ) => { const routeParams = { } ; if ( item . path ) { const routePath = joinPath ( parentPath || '' , item . path ) ; routeParams . path = routePath === '/' ? '/' : routePath . replace ( /\/$/ , '' ) ; } if ( item . children ) { routeParams . children = formatRoutes ( item . children , routeParams . path || item . path ) ; } else if ( item . component ) { const itemComponent = item . component as any ; itemComponent . pageConfig = Object . assign ( { } , itemComponent . pageConfig , { componentName : itemComponent . name } ) ; } return { ... item , ... routeParams , } ; } ) ; }