import {defineComponent} from 'vue'; import {filterEmpty, getComponentFromContext} from '../_util/props-util'; import {cloneElement} from '../_util/vnode'; import PropTypes from '../_util/vue-types'; import {useConfigProvider} from '../config-provider'; import Menu from '../menu'; import BreadcrumbItem from './breadcrumb-item'; const MenuItem = Menu.Item; const Route = PropTypes.shape({ path: PropTypes.string, breadcrumbName: PropTypes.string, children: PropTypes.array }).loose; const BreadcrumbProps = { prefixCls: PropTypes.string, routes: PropTypes.arrayOf(Route), params: PropTypes.any, separator: PropTypes.any, itemRender: PropTypes.func }; function getBreadcrumbName(route, params) { if (!route.breadcrumbName) { return null; } const paramsKeys = Object.keys(params).join('|'); const name = route.breadcrumbName.replace( new RegExp(`:(${paramsKeys})`, 'g'), (replacement, key) => params[key] || replacement ); return name; } export default defineComponent({ name: 'ABreadcrumb', props: BreadcrumbProps, setup($props, {emit}) { const defaultItemRender = ({route, params, routes, paths}) => { const isLastItem = routes.indexOf(route) === routes.length - 1; const name = getBreadcrumbName(route, params); return isLastItem ? {name} : {name}; }; const getPath = (path, params) => { let copyPath = path; copyPath = (copyPath || '').replace(/^\//, ''); Object.keys(params).forEach(key => { copyPath = copyPath.replace(`:${key}`, params[key]); }); return copyPath; }; const addChildPath = (paths, childPath, params) => { const originalPaths = [...paths]; const path = getPath(childPath, params); if (path) { originalPaths.push(path); } return originalPaths; }; const genForRoutes = ({routes = [], params = {}, separator, itemRender = defaultItemRender}) => { const paths = []; return routes.map(route => { const path = getPath(route.path, params); if (path) { paths.push(path); } // generated overlay by route.children let overlay = null; if (route.children && route.children.length) { overlay = (
); } return (