From d1306b1cb6dd60a2299747e9ae9f405a031270ac Mon Sep 17 00:00:00 2001 From: Christopher Buecheler Date: Wed, 28 Oct 2015 11:06:52 -0400 Subject: [PATCH] [fixed] Support LinkContainer without history --- src/LinkContainer.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/LinkContainer.js b/src/LinkContainer.js index 8723a71..5c8b1bd 100644 --- a/src/LinkContainer.js +++ b/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 = {