diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx
index dc68a37475..7e16436b90 100755
--- a/components/breadcrumb/Breadcrumb.tsx
+++ b/components/breadcrumb/Breadcrumb.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
+import toArray from 'rc-util/lib/Children/toArray';
import BreadcrumbItem from './BreadcrumbItem';
import BreadcrumbSeparator from './BreadcrumbSeparator';
import Menu from '../menu';
@@ -47,6 +48,16 @@ function defaultItemRender(route: Route, params: any, routes: Route[], paths: st
return isLastItem ? {name} : {name};
}
+function filterFragment(children: any) {
+ return toArray(children).map((element: any) => {
+ if (React.isValidElement(element) && element.type === React.Fragment) {
+ const props: any = element.props;
+ return props.children;
+ }
+ return element;
+ });
+}
+
export default class Breadcrumb extends React.Component {
static Item: typeof BreadcrumbItem;
@@ -139,7 +150,7 @@ export default class Breadcrumb extends React.Component {
// generated by route
crumbs = this.genForRoutes(this.props);
} else if (children) {
- crumbs = React.Children.map(children, (element: any, index) => {
+ crumbs = React.Children.map(filterFragment(children), (element: any, index) => {
if (!element) {
return element;
}
diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.js b/components/breadcrumb/__tests__/Breadcrumb.test.js
index 83f626c688..4c6d1e2a94 100644
--- a/components/breadcrumb/__tests__/Breadcrumb.test.js
+++ b/components/breadcrumb/__tests__/Breadcrumb.test.js
@@ -52,6 +52,21 @@ describe('Breadcrumb', () => {
expect(wrapper).toMatchSnapshot();
});
+ // https://github.com/ant-design/ant-design/issues/18260
+ it('filter React.Fragment', () => {
+ const wrapper = render(
+
+ Location
+ :
+ <>
+ Application Center
+
+ >
+ ,
+ );
+ expect(wrapper).toMatchSnapshot();
+ });
+
it('should render a menu', () => {
const routes = [
{
diff --git a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap
index c5cb3931cc..ae829f58a4 100644
--- a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap
+++ b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.js.snap
@@ -1,5 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`Breadcrumb filter React.Fragment 1`] = `
+
+`;
+
exports[`Breadcrumb should allow Breadcrumb.Item is null or undefined 1`] = `