Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleClick(e) {
const { onClick, target, to, href, qs } = this.props;
const { linkProvider, history } = this.context;
if (isMiddleClickEvent(e)) {
return;
}
if (onClick) onClick(e);
if (e.defaultPrevented === true) return;
if (isModifiedEvent(e) || !isLeftClickEvent(e)) return;
const url = composeUrl({ url: to || href, qs });
if (url == null) return;
if (target === '_blank' || isAbsoluteUrl(url)) return;
e.preventDefault();
if (history) {
history.push(url);
} else if (linkProvider) {
linkProvider.onClick(url, e);
} else {
console.error('Link without linkProvider (history)'); // eslint-disable-line no-console
window.location = url;
}
}
render() {
const { to, href, qs, children, ...props } = this.props;
const url = composeUrl({ url: to || href, qs });
return <a href="{url}">{children}</a>;
}
}