Skip to content

Commit 188b60e

Browse files
author
Justin Schrader
authored
Merge pull request #5 from icd2k3/fix-root-route
Fix root route
2 parents 6deeb79 + 9904af7 commit 188b60e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/index.jsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { createElement } from 'react';
22
import { matchPath, withRouter } from 'react-router';
33

44
const DEFAULT_MATCH_OPTIONS = { exact: true };
@@ -23,7 +23,7 @@ export const getBreadcrumbs = ({ routes, pathname }) => {
2323
// combine the last route section with the current
2424
// ex `pathname = /1/2/3 results in match checks for
2525
// `/1`, `/1/2`, `/1/2/3`
26-
const pathSection = current === '' ? '/' : `${previous}/${current}`;
26+
const pathSection = !current ? '/' : `${previous}/${current}`;
2727

2828
let breadcrumbMatch;
2929

@@ -53,19 +53,16 @@ export const getBreadcrumbs = ({ routes, pathname }) => {
5353
}
5454

5555
return pathSection === '/' ? '' : pathSection;
56-
}, '');
56+
}, null);
5757

5858
return matches;
5959
};
6060

61-
export const withBreadcrumbs = routes => Component => withRouter(props => (
62-
<Component
63-
{...props}
64-
breadcrumbs={
65-
getBreadcrumbs({
66-
pathname: props.location.pathname,
67-
routes,
68-
})
69-
}
70-
/>
71-
));
61+
export const withBreadcrumbs = routes => Component => withRouter(props =>
62+
createElement(Component, {
63+
...props,
64+
breadcrumbs: getBreadcrumbs({
65+
pathname: props.location.pathname,
66+
routes,
67+
}),
68+
}));

0 commit comments

Comments
 (0)