2017-05-03 01:04:16 +01:00
|
|
|
import React from 'react';
|
2017-04-21 19:05:35 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-05-03 01:04:16 +01:00
|
|
|
class Permalink extends React.PureComponent {
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-04-21 19:05:35 +01:00
|
|
|
constructor (props, context) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
}
|
2016-12-02 14:05:50 +00:00
|
|
|
|
|
|
|
handleClick (e) {
|
|
|
|
if (e.button === 0) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.context.router.push(this.props.to);
|
|
|
|
}
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|
2016-12-02 14:05:50 +00:00
|
|
|
|
|
|
|
render () {
|
2017-04-23 03:26:55 +01:00
|
|
|
const { href, children, className, ...other } = this.props;
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-05-03 01:04:16 +01:00
|
|
|
return (
|
|
|
|
<a href={href} onClick={this.handleClick} {...other} className={'permalink ' + className}>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
2016-12-02 14:05:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Permalink.contextTypes = {
|
|
|
|
router: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
Permalink.propTypes = {
|
2017-04-23 03:26:55 +01:00
|
|
|
className: PropTypes.string,
|
2017-04-21 19:05:35 +01:00
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string.isRequired,
|
|
|
|
children: PropTypes.node
|
|
|
|
};
|
2016-12-02 14:05:50 +00:00
|
|
|
|
|
|
|
export default Permalink;
|