You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
834 B

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. class Permalink extends React.PureComponent {
  4. constructor (props, context) {
  5. super(props, context);
  6. this.handleClick = this.handleClick.bind(this);
  7. }
  8. handleClick (e) {
  9. if (e.button === 0) {
  10. e.preventDefault();
  11. this.context.router.push(this.props.to);
  12. }
  13. }
  14. render () {
  15. const { href, children, className, ...other } = this.props;
  16. return (
  17. <a href={href} onClick={this.handleClick} {...other} className={'permalink ' + className}>
  18. {children}
  19. </a>
  20. );
  21. }
  22. }
  23. Permalink.contextTypes = {
  24. router: PropTypes.object
  25. };
  26. Permalink.propTypes = {
  27. className: PropTypes.string,
  28. href: PropTypes.string.isRequired,
  29. to: PropTypes.string.isRequired,
  30. children: PropTypes.node
  31. };
  32. export default Permalink;