Skip to content
This repository was archived by the owner on Aug 2, 2020. It is now read-only.

Commit 5533242

Browse files
authored
Merge pull request #13 from zhonghuiwen/master
Added routeMatcherRegex prop to allow customization for routeMatcher
2 parents 1b47714 + d185d72 commit 5533242

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class App extends Component {
123123
WrapperComponent={(props) => <ol className="breadcrumb" >{props.children}</ol>}
124124
ActiveLinkComponent={(props) => <li className="active" >{props.children}</li>}
125125
LinkComponent={(props) => <li>{props.children}</li>} // Don't create link tag or <Link />. Component will wrapp props.children with <Link />
126-
mappedRoutes={routes} />
126+
mappedRoutes={routes}
127+
routeMatcherRegex="([\w-]+)" />
127128
</Router>
128129
);
129130
}
@@ -140,6 +141,7 @@ class App extends Component {
140141
| `ActiveLinkComponent` | function | Function responsible for creating active link html structure. Expected signature: `(props) => <JSX>{props.children}</JSX> PropTypes.func` |
141142
| `LinkComponent` | function | Function responsible for creating link html structure. Expected signature: `(props) => <JSX>{props.children}</JSX> PropTypes.func` |
142143
| `rootName` | string &#124; function | If set, root breadcrumb will always be displayed with given caption.<br/>If function is provided, it's resolved at display time, as with any other breadcrumbs, but it receives a full location path as `url` and `null` as `match`<br/>Empty string, `false` or `null` will hide it (**default**) |
144+
| `routeMatcherRegex` | string | Customize routeMatcher by regular expression. <br/>e.g. If you want to accept the pipe character "&#124;", you can pass in <code>"([\\w-&#124;]+)"</code> <br/> By default routeMatcherRegex is set to `'([\\w-]+)'`
143145

144146

145147

dist/BreadcrumbsItem.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ var BreadcrumbsItem = function BreadcrumbsItem(props) {
2828
mappedRoutes = props.mappedRoutes;
2929
var _props$parentProps = props.parentProps,
3030
ActiveLinkComponent = _props$parentProps.ActiveLinkComponent,
31-
LinkComponent = _props$parentProps.LinkComponent;
31+
LinkComponent = _props$parentProps.LinkComponent,
32+
routeMatcherRegex = _props$parentProps.routeMatcherRegex;
3233

3334
var placeholderMatcher = /:[^\s/]+/g;
3435

3536
var getPlaceholderVars = function getPlaceholderVars(url, key) {
3637
var placeholders = key.match(placeholderMatcher);
3738
if (!placeholders) return null;
38-
var routeMatcher = new RegExp('^' + key.replace(placeholderMatcher, '([\\w-]+)') + '$');
39+
var routeMatcher = new RegExp('^' + key.replace(placeholderMatcher, routeMatcherRegex || '([\\w-]+)') + '$');
3940
var match = url.match(routeMatcher);
4041
if (!match) return null;
4142
return placeholders.reduce(function (memo, placeholder, index, array) {

dist/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var BreadcrumbsWrapper = function BreadcrumbsWrapper(props) {
3030
WrapperComponent: props.WrapperComponent,
3131
ActiveLinkComponent: props.ActiveLinkComponent,
3232
LinkComponent: props.LinkComponent,
33-
rootName: props.rootName
33+
rootName: props.rootName,
34+
routeMatcherRegex: props.routeMatcherRegex
3435
}, rest));
3536
}
3637
});
@@ -66,7 +67,8 @@ BreadcrumbsWrapper.propTypes = {
6667
WrapperComponent: _propTypes2.default.func,
6768
ActiveLinkComponent: _propTypes2.default.func,
6869
LinkComponent: _propTypes2.default.func,
69-
rootName: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func])
70+
rootName: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
71+
routeMatcherRegex: _propTypes2.default.string
7072
};
7173

7274
exports.default = BreadcrumbsWrapper;

src/BreadcrumbsItem.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import PropTypes from 'prop-types';
55
export const isDefined = v => (v !== undefined && v !== null && v !== false && String(v).length > 0);
66
const BreadcrumbsItem = (props) => {
77
const {match, name, mappedRoutes} = props;
8-
const {ActiveLinkComponent, LinkComponent} = props.parentProps;
8+
const {ActiveLinkComponent, LinkComponent, routeMatcherRegex} = props.parentProps;
99
const placeholderMatcher = /:[^\s/]+/g;
1010

1111
const getPlaceholderVars = (url, key) => {
1212
const placeholders = key.match(placeholderMatcher);
1313
if (!placeholders)
1414
return null;
15-
const routeMatcher = new RegExp('^' + key.replace(placeholderMatcher, '([\\w-]+)') + '$');
15+
const routeMatcher = new RegExp('^' + key.replace(placeholderMatcher, routeMatcherRegex || '([\\w-]+)') + '$');
1616
const match = url.match(routeMatcher);
1717
if (!match)
1818
return null;
@@ -95,4 +95,5 @@ BreadcrumbsItem.propTypes = {
9595
parentProps: PropTypes.shape({}).isRequired,
9696
};
9797

98+
9899
export default BreadcrumbsItem;

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const BreadcrumbsWrapper = (props) => {
1212
ActiveLinkComponent={props.ActiveLinkComponent}
1313
LinkComponent={props.LinkComponent}
1414
rootName={props.rootName}
15+
routeMatcherRegex={props.routeMatcherRegex}
1516
{...rest}
1617
/>}
1718
/>
@@ -31,7 +32,8 @@ BreadcrumbsWrapper.propTypes = {
3132
WrapperComponent: PropTypes.func,
3233
ActiveLinkComponent: PropTypes.func,
3334
LinkComponent: PropTypes.func,
34-
rootName: PropTypes.oneOfType([PropTypes.string,PropTypes.func])
35+
rootName: PropTypes.oneOfType([PropTypes.string,PropTypes.func]),
36+
routeMatcherRegex: PropTypes.string,
3537
};
3638

3739
export default BreadcrumbsWrapper;

0 commit comments

Comments
 (0)