import React, { FC } from "react"; import { withRouter, RouteComponentProps } from "react-router-dom"; import { Breadcrumb } from "antd"; import { getBreadcrumbRoutes } from "@/router/utils"; import arrowRight from "@/assets/images/ico_arrow@2x.png"; import "./index.scss"; type P = RouteComponentProps & { className?: string; style?: object; showCurrentPosition?: boolean; routes?: { path?: string; name: string; }[]; }; const { Separator, Item } = Breadcrumb; const CustBreadcrumb: FC

= props => { const path = props.match.path || props.location.pathname; //默认路由 const _defaultRoutes = getBreadcrumbRoutes(path); const { routes = _defaultRoutes, style = {}, className = "", showCurrentPosition } = props; if (!routes.length) return null; return ( {//显示当前位置 showCurrentPosition && 当前位置} {showCurrentPosition && :} {routes.map((item, index) => { const children = []; if (index !== 0) { children.push( 分隔符 ); } //最后一个不能点击 children.push( { if (index !== routes.length - 1 && item.path) { props.history.push(item.path); } }} > {index !== routes.length - 1 ? {item.name} : item.name} ); return children; })} ); }; export default withRouter(CustBreadcrumb);