|
|
@ -46,9 +46,9 @@ export type ItemType = Partial<BreadcrumbItemType & BreadcrumbSeparatorType>; |
|
|
|
|
|
|
|
export type InternalRouteType = Partial<BreadcrumbItemType & BreadcrumbSeparatorType>; |
|
|
|
|
|
|
|
export interface BreadcrumbProps { |
|
|
|
export interface BreadcrumbProps<T extends Record<PropertyKey, any> = any> { |
|
|
|
prefixCls?: string; |
|
|
|
params?: any; |
|
|
|
params?: T; |
|
|
|
separator?: React.ReactNode; |
|
|
|
style?: React.CSSProperties; |
|
|
|
className?: string; |
|
|
@ -60,19 +60,13 @@ export interface BreadcrumbProps { |
|
|
|
|
|
|
|
items?: ItemType[]; |
|
|
|
|
|
|
|
itemRender?: ( |
|
|
|
route: ItemType, |
|
|
|
params: any, |
|
|
|
routes: ItemType[], |
|
|
|
paths: string[], |
|
|
|
) => React.ReactNode; |
|
|
|
itemRender?: (route: ItemType, params: T, routes: ItemType[], paths: string[]) => React.ReactNode; |
|
|
|
} |
|
|
|
|
|
|
|
const getPath = (params: any, path?: string) => { |
|
|
|
const getPath = <T extends Record<PropertyKey, any> = any>(params: T, path?: string) => { |
|
|
|
if (path === undefined) { |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
let mergedPath = (path || '').replace(/^\//, ''); |
|
|
|
Object.keys(params).forEach((key) => { |
|
|
|
mergedPath = mergedPath.replace(`:${key}`, params[key]!); |
|
|
@ -80,7 +74,7 @@ const getPath = (params: any, path?: string) => { |
|
|
|
return mergedPath; |
|
|
|
}; |
|
|
|
|
|
|
|
const Breadcrumb = (props: BreadcrumbProps) => { |
|
|
|
const Breadcrumb = <T extends Record<PropertyKey, any> = any>(props: BreadcrumbProps<T>) => { |
|
|
|
const { |
|
|
|
prefixCls: customizePrefixCls, |
|
|
|
separator = '/', |
|
|
@ -113,7 +107,7 @@ const Breadcrumb = (props: BreadcrumbProps) => { |
|
|
|
// generated by route
|
|
|
|
const paths: string[] = []; |
|
|
|
|
|
|
|
const itemRenderRoutes: any = items || legacyRoutes; |
|
|
|
const itemRenderRoutes = items || legacyRoutes; |
|
|
|
|
|
|
|
crumbs = mergedItems.map((item, index) => { |
|
|
|
const { |
|
|
@ -168,7 +162,7 @@ const Breadcrumb = (props: BreadcrumbProps) => { |
|
|
|
onClick={onClick} |
|
|
|
prefixCls={prefixCls} |
|
|
|
> |
|
|
|
{mergedItemRender(item as BreadcrumbItemType, params, itemRenderRoutes, paths, href)} |
|
|
|
{mergedItemRender(item, params, itemRenderRoutes!, paths, href)} |
|
|
|
</InternalBreadcrumbItem> |
|
|
|
); |
|
|
|
}); |
|
|
|