about summary refs log tree commit diff
path: root/app/assets/javascripts/components/components/permalink.jsx
blob: ae2fb0d29c8b2f6fa0369b78a5bcfd6d14b2dae1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const Permalink = React.createClass({

  contextTypes: {
    router: React.PropTypes.object
  },

  propTypes: {
    href: React.PropTypes.string.isRequired,
    to: React.PropTypes.string.isRequired
  },

  handleClick (e) {
    if (e.button === 0) {
      e.preventDefault();
      this.context.router.push(this.props.to);
    }
  },

  render () {
    const { href, children, ...other } = this.props;

    return <a href={href} onClick={this.handleClick} {...other}>{children}</a>;
  }

});

export default Permalink;