Skip to content
Browse files

[fixed] Support LinkContainer without history

  • Loading branch information...
1 parent dfe8c44 commit d1306b1cb6dd60a2299747e9ae9f405a031270ac @cwbuecheler cwbuecheler committed with taion
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/LinkContainer.js
View
16 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

Please sign in to comment.
Something went wrong with that request. Please try again.