11import type { DBreadcrumbItem } from '@react-devui/ui/components/breadcrumb' ;
22
3+ import React from 'react' ;
34import { useTranslation } from 'react-i18next' ;
45import { Link } from 'react-router-dom' ;
56
67import { DBreadcrumb } from '@react-devui/ui' ;
78import { getClassName } from '@react-devui/utils' ;
89
10+ type BreadcrumbItem = DBreadcrumbItem < string > & { skipRenderLink ?: boolean } ;
11+
912export interface AppRouteHeaderBreadcrumbProps extends Omit < React . HTMLAttributes < HTMLDivElement > , 'children' > {
10- aList : DBreadcrumbItem < string > [ ] ;
11- aHome ?: DBreadcrumbItem < string > ;
13+ aList : BreadcrumbItem [ ] ;
14+ aHome ?: BreadcrumbItem ;
1215 aSeparator ?: React . ReactNode ;
1316}
1417
@@ -23,7 +26,7 @@ export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps):
2326
2427 const { t } = useTranslation ( ) ;
2528
26- const home : DBreadcrumbItem < string > = aHome ?? {
29+ const home : BreadcrumbItem = aHome ?? {
2730 id : '/' ,
2831 title : t ( 'Home' , { ns : 'title' } ) ,
2932 link : true ,
@@ -34,13 +37,18 @@ export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps):
3437 < DBreadcrumb
3538 dList = { [ home ] . concat ( aList ) . map ( ( item ) => ( {
3639 ...item ,
37- title : item . link ? (
38- < Link className = "app-route-header__breadcrumb-link" to = { item . id } >
39- { item . title }
40- </ Link >
41- ) : (
42- item . title
43- ) ,
40+ title :
41+ item . link && ! item . skipRenderLink ? (
42+ < Link className = "app-route-header__breadcrumb-link" to = { item . id } >
43+ { item . title }
44+ </ Link >
45+ ) : React . isValidElement ( item . title ) ? (
46+ React . cloneElement < React . HTMLAttributes < HTMLElement > > ( item . title as any , {
47+ className : getClassName ( item . title . props . className , 'app-route-header__breadcrumb-item' ) ,
48+ } )
49+ ) : (
50+ < div className = "app-route-header__breadcrumb-item" > { item . title } </ div >
51+ ) ,
4452 } ) ) }
4553 dSeparator = { aSeparator }
4654 />
0 commit comments