Skip to content

Commit deb0acf

Browse files
committed
Add support for hash prop
1 parent 0648cb2 commit deb0acf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/LinkContainer.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ export default class LinkContainer extends React.Component {
2525

2626
render() {
2727
const {history} = this.context;
28-
const {onlyActiveOnIndex, to, query, children, ...props} = this.props;
28+
const {onlyActiveOnIndex, to, query, hash, children, ...props} =
29+
this.props;
2930

3031
delete props.state;
31-
delete props.onClick;
32+
3233
props.onClick = this.onClick;
3334
props.href = history.createHref(to, query);
35+
if (hash) {
36+
props.href += hash;
37+
}
3438
props.active = history.isActive(to, query, onlyActiveOnIndex);
3539

3640
return React.cloneElement(React.Children.only(children), props);
@@ -41,6 +45,7 @@ LinkContainer.propTypes = {
4145
onlyActiveOnIndex: React.PropTypes.bool.isRequired,
4246
to: React.PropTypes.string.isRequired,
4347
query: React.PropTypes.object,
48+
hash: React.PropTypes.string,
4449
state: React.PropTypes.object,
4550
onClick: React.PropTypes.func,
4651
disabled: React.PropTypes.bool.isRequired,

tests/LinkContainer.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('LinkContainer', () => {
1919
class LinkWrapper extends React.Component {
2020
render() {
2121
return (
22-
<LinkContainer to="/foo" query={{bar: 'baz'}}>
22+
<LinkContainer to="/foo" query={{bar: 'baz'}} hash="#the-hash">
2323
<Component>Foo</Component>
2424
</LinkContainer>
2525
);
@@ -35,7 +35,7 @@ describe('LinkContainer', () => {
3535
const anchor = ReactTestUtils.findRenderedDOMComponentWithTag(
3636
router, 'A'
3737
);
38-
expect(anchor.getAttribute('href')).to.equal('/foo?bar=baz');
38+
expect(anchor.getAttribute('href')).to.equal('/foo?bar=baz#the-hash');
3939
});
4040

4141
it('should not add extra DOM nodes', () => {

0 commit comments

Comments
 (0)