You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

2 years ago
  1. import React, { FC } from 'react'
  2. import { useHistory } from 'react-router-dom'
  3. import withBreadcrumbs from 'react-router-breadcrumbs-hoc'
  4. import { Breadcrumb, Button } from 'antd'
  5. import routes from '@/route/routes'
  6. import { flattenRoutes } from '@/assets/js/publicFunc'
  7. const allRoutes = flattenRoutes(routes)
  8. interface Props {
  9. breadcrumbs: any[];
  10. }
  11. // 通用面包屑
  12. const Breadcrumbs: FC<Props> = ({ breadcrumbs }) => {
  13. const history = useHistory()
  14. return (
  15. <Breadcrumb style={{ display: 'inline-block' }}>
  16. {breadcrumbs.map((bc: CommonObjectType, index: number) => {
  17. return (
  18. <Breadcrumb.Item key={bc.key}>
  19. <Button
  20. disabled={
  21. (!bc.exact && bc.match.path !== '/') ||
  22. index === breadcrumbs.length - 1
  23. }
  24. onClick={() => {
  25. history.push(bc.match.path)
  26. }}
  27. style={{ padding: '0' }}
  28. type="link"
  29. >
  30. {bc.name}
  31. </Button>
  32. </Breadcrumb.Item>
  33. )
  34. })}
  35. </Breadcrumb>
  36. )
  37. }
  38. export default withBreadcrumbs(allRoutes)(Breadcrumbs)