import routes , { IRoute } from './config' ; import config from '../config' ; param routeList param deep param auth export function flattenRoute ( routeList , deep , auth ) { const result = [ ] ; for ( let i = 0 ; i < routeList . length ; i += 1 ) { const route = routeList [ i ] ; result . push ( { ... route , auth : typeof route . auth !== 'undefined' ? route . auth : auth , } ) ; if ( route . children && deep ) { result . push ( ... flattenRoute ( route . children , deep , auth ) ) ; } } return result ; } function getLayoutRouteList ( ) { return flattenRoute ( routes , false , false ) ; } function getBusinessRouteList ( ) { const routeList = routes . filter ( route => route . path === '/' ) ; if ( routeList . length > 0 ) { return flattenRoute ( routeList , true , true ) ; } return [ ] ; } function getSystemRouteList ( ) { const routeList = routes . filter ( route => route . path === '/system' ) ; if ( routeList . length > 0 ) { return flattenRoute ( routeList , true , false ) ; } return [ ] ; } /**
 * 这里会将 config 中所有路由解析成三个数组
 * 第一个: 最外层的路由，例如  Layout UserLayout ...
 * 第二个: 系统路由, 例如 Login Register RegisterResult
 * 第三个: 业务路由，为 / 路由下的业务路由
 */ export const layoutRouteList = getLayoutRouteList ( ) ; export const businessRouteList = getBusinessRouteList ( ) ; export const systemRouteList = getSystemRouteList ( ) ; function findRoutesByPaths ( pathList , routeList , basename ? ) { return routeList . filter ( ( child ) => pathList . indexOf ( ( basename || '' ) + child . path ) !== - 1 ) ; } export function getPageTitle ( routeList ) { const route = routeList . find ( child => child . path === window . location . pathname ) ; return route ? route . meta . title : '' ; } export function getPagePathList ( pathname ? ) { return ( pathname || window . location . pathname ) . split ( '/' ) . filter ( Boolean ) . map ( ( value , index , array ) => '/' . concat ( array . slice ( 0 , index + 1 ) . join ( '/' ) ) ) ; } /**
 * 只有业务路由会有面包屑
 */ export function getBreadcrumbs ( ) { return findRoutesByPaths ( getPagePathList ( ) , businessRouteList , config . BASENAME ) ; }