Updates routes in breadcrumbs so they no longer use the render prop

This commit is contained in:
mabashian 2020-04-07 16:39:14 -04:00
parent 193ec21149
commit 7feac5ecd6

View File

@ -7,7 +7,8 @@ import {
BreadcrumbItem,
BreadcrumbHeading,
} from '@patternfly/react-core';
import { Link, Route, withRouter } from 'react-router-dom';
import { Link, Route, withRouter, useRouteMatch } from 'react-router-dom';
import styled from 'styled-components';
const PageSection = styled(PFPageSection)`
@ -15,18 +16,15 @@ const PageSection = styled(PFPageSection)`
padding-bottom: 10px;
`;
const Breadcrumbs = ({ breadcrumbConfig }) => {
const Breadcrumbs = ({ breadcrumbConfig, match }) => {
const { light } = PageSectionVariants;
return (
<PageSection variant={light}>
<Breadcrumb>
<Route
path="/:path"
render={props => (
<Crumb breadcrumbConfig={breadcrumbConfig} {...props} />
)}
/>
<Route path="/:path">
<Crumb breadcrumbConfig={breadcrumbConfig} match={match} />
</Route>
</Breadcrumb>
</PageSection>
);
@ -51,15 +49,17 @@ const Crumb = ({ breadcrumbConfig, match }) => {
crumbElement = null;
}
function NextCrumb() {
const routeMatch = useRouteMatch();
return <Crumb breadcrumbConfig={breadcrumbConfig} match={routeMatch} />;
}
return (
<Fragment>
{crumbElement}
<Route
path={`${match.url}/:path`}
render={props => (
<Crumb breadcrumbConfig={breadcrumbConfig} {...props} />
)}
/>
<Route path={`${match.url}/:path`}>
<NextCrumb />
</Route>
</Fragment>
);
};