2017-05-03 00:04:16 +00:00
|
|
|
import React from 'react';
|
2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-05-03 00:04:16 +00:00
|
|
|
class Permalink extends React.PureComponent {
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-05-12 12:44:10 +00:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string.isRequired,
|
|
|
|
children: PropTypes.node
|
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = (e) => {
|
2017-05-15 20:36:38 +00:00
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
2016-12-02 14:05:50 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.context.router.push(this.props.to);
|
|
|
|
}
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-12-02 14:05:50 +00:00
|
|
|
|
|
|
|
render () {
|
2017-04-23 02:26:55 +00:00
|
|
|
const { href, children, className, ...other } = this.props;
|
2016-12-02 14:05:50 +00:00
|
|
|
|
2017-05-03 00:04:16 +00: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 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:05:50 +00:00
|
|
|
export default Permalink;
|