Permalink
Browse files
[fixed] Support LinkContainer without history
- Loading branch information...
Showing
with
11 additions
and
5 deletions.
-
+11
−5
src/LinkContainer.js
|
@@ -31,11 +31,17 @@ export default class LinkContainer extends React.Component { |
|
|
delete props.state;
|
|
|
|
|
|
props.onClick = this.onClick;
|
|
|
- props.href = history.createHref(to, query);
|
|
|
- if (hash) {
|
|
|
- props.href += hash;
|
|
|
+
|
|
|
+ // Ignore if rendered outside the context of history, simplifies unit testing.
|
|
|
+ if (history) {
|
|
|
+ props.href = history.createHref(to, query);
|
|
|
+
|
|
|
+ if (hash) {
|
|
|
+ props.href += hash;
|
|
|
+ }
|
|
|
+
|
|
|
+ props.active = history.isActive(to, query, onlyActiveOnIndex);
|
|
|
}
|
|
|
- props.active = history.isActive(to, query, onlyActiveOnIndex);
|
|
|
|
|
|
return React.cloneElement(React.Children.only(children), props);
|
|
|
}
|
|
@@ -53,7 +59,7 @@ LinkContainer.propTypes = { |
|
|
};
|
|
|
|
|
|
LinkContainer.contextTypes = {
|
|
|
- history: React.PropTypes.object.isRequired
|
|
|
+ history: React.PropTypes.object
|
|
|
};
|
|
|
|
|
|
LinkContainer.defaultProps = {
|
|
|
0 comments on commit
d1306b1