Skip to content

Commit e6bdd7d

Browse files
authored
fix: issue with excludePaths and update dependencies (#80)
* fix: issue with excludePaths and update dependencies * bump version
1 parent 8726f81 commit e6bdd7d

File tree

7 files changed

+678
-1486
lines changed

7 files changed

+678
-1486
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"react/destructuring-assignment": 0,
88
"react/jsx-one-expression-per-line": 0,
99
"react/jsx-filename-extension": 0,
10-
"react/no-multi-comp": 0
10+
"react/no-multi-comp": 0,
11+
"react/jsx-props-no-spreading": 0
1112
},
1213
"globals": {
1314
"jest": "writeable"

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
src/
22
coverage/
33
/yarn-error.log
4+
scripts/
5+
hooks/
6+
coverage/

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router-breadcrumbs-hoc",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "small, flexible, higher order component for rendering breadcrumbs with react-router 4.x",
55
"repository": "icd2k3/react-router-breadcrumbs-hoc",
66
"main": "dist/cjs/index.js",
@@ -48,16 +48,16 @@
4848
"enzyme": "^3.10.0",
4949
"enzyme-adapter-react-16": "^1.14.0",
5050
"eslint": "^6.0.1",
51-
"eslint-config-airbnb": "^17.1.1",
51+
"eslint-config-airbnb": "^18.0.1",
5252
"eslint-plugin-import": "^2.18.1",
5353
"eslint-plugin-jsx-a11y": "^6.2.3",
5454
"eslint-plugin-react": "^7.14.2",
5555
"husky": "^3.0.1",
5656
"jest": "^24.8.0",
5757
"js-yaml": "^3.13.1",
5858
"prop-types": "^15.7.2",
59-
"react": "16.8.6",
60-
"react-dom": "16.8.6",
59+
"react": "16.9.0",
60+
"react-dom": "16.9.0",
6161
"react-router": "^5.0.1",
6262
"react-router-dom": "^5.0.1",
6363
"rollup": "^1.17.0",

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const globals = {
2727
'react-router': 'ReactRouter',
2828
};
2929

30-
export default exports.map(item => ({
30+
export default exports.map((item) => ({
3131
input: 'src/index.js',
3232
plugins: item.plugins,
3333
external,

src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ const NO_BREADCRUMB = 'NO_BREADCRUMB';
2929
* we used to use the humanize-string package, but it added a lot of bundle
3030
* size and issues with compilation. This 4-liner seems to cover most cases.
3131
*/
32-
const humanize = str => str
32+
const humanize = (str) => str
3333
.replace(/^[\s_]+|[\s_]+$/g, '')
3434
.replace(/[_\s]+/g, ' ')
35-
.replace(/^[a-z]/, m => m.toUpperCase());
35+
.replace(/^[a-z]/, (m) => m.toUpperCase());
3636

3737
/**
3838
* Renders and returns the breadcrumb complete
@@ -84,7 +84,8 @@ const getBreadcrumbMatch = ({
8484

8585
// Check the optional `exludePaths` option in `options` to see if the
8686
// current path should not include a breadcrumb.
87-
if (excludePaths && excludePaths.includes(pathSection)) {
87+
const getIsPathExcluded = (path) => matchPath(pathSection, { path, exact: true, strict: false });
88+
if (excludePaths && excludePaths.some(getIsPathExcluded)) {
8889
return NO_BREADCRUMB;
8990
}
9091

@@ -192,18 +193,20 @@ export const getBreadcrumbs = ({ routes, location, options = {} }) => {
192193
* Takes a route array and recursively flattens it IF there are
193194
* nested routes in the config.
194195
*/
195-
const flattenRoutes = routes => (routes || []).reduce((arr, route) => {
196+
const flattenRoutes = (routes) => (routes || []).reduce((arr, route) => {
196197
if (route.routes) {
197198
return arr.concat([route, ...flattenRoutes(route.routes)]);
198199
}
199200
return arr.concat(route);
200201
}, []);
201202

202-
export default (routes = [], options) => Component => withRouter(props => createElement(Component, {
203-
...props,
204-
breadcrumbs: getBreadcrumbs({
205-
routes: flattenRoutes(routes),
206-
location: props.location,
207-
options,
203+
export default (routes = [], options) => (Component) => withRouter(
204+
(props) => createElement(Component, {
205+
...props,
206+
breadcrumbs: getBreadcrumbs({
207+
routes: flattenRoutes(routes),
208+
location: props.location,
209+
options,
210+
}),
208211
}),
209-
}));
212+
);

src/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ describe('react-router-breadcrumbs-hoc', () => {
309309
const { breadcrumbs } = render({ pathname: '/one/two', options: { excludePaths: ['/', '/one'] } });
310310
expect(breadcrumbs).toBe('Two');
311311
});
312+
313+
it('Should work with url params', () => {
314+
const routes = [
315+
{ path: '/a' },
316+
{ path: '/a/:b' },
317+
{ path: '/a/:b/:c' },
318+
];
319+
const { breadcrumbs } = render({
320+
pathname: '/a/b/c',
321+
routes,
322+
options: { excludePaths: ['/a/:b', '/a'] },
323+
});
324+
expect(breadcrumbs).toBe('Home / C');
325+
});
312326
});
313327

314328
describe('options without routes array', () => {

0 commit comments

Comments
 (0)