闭社主体 forked from https://github.com/tootsuite/mastodon
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.

34 lines
761 B

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