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.
42 lines
834 B
42 lines
834 B
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
|
||
8 years ago
|
class Permalink extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
constructor (props, context) {
|
||
|
super(props, context);
|
||
|
this.handleClick = this.handleClick.bind(this);
|
||
|
}
|
||
8 years ago
|
|
||
|
handleClick (e) {
|
||
|
if (e.button === 0) {
|
||
|
e.preventDefault();
|
||
|
this.context.router.push(this.props.to);
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
render () {
|
||
8 years ago
|
const { href, children, className, ...other } = this.props;
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
|
<a href={href} onClick={this.handleClick} {...other} className={'permalink ' + className}>
|
||
|
{children}
|
||
|
</a>
|
||
|
);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
}
|
||
|
|
||
|
Permalink.contextTypes = {
|
||
|
router: PropTypes.object
|
||
|
};
|
||
|
|
||
|
Permalink.propTypes = {
|
||
8 years ago
|
className: PropTypes.string,
|
||
8 years ago
|
href: PropTypes.string.isRequired,
|
||
|
to: PropTypes.string.isRequired,
|
||
|
children: PropTypes.node
|
||
|
};
|
||
8 years ago
|
|
||
|
export default Permalink;
|