-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLinkComponent.js
More file actions
37 lines (32 loc) · 934 Bytes
/
LinkComponent.js
File metadata and controls
37 lines (32 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react'
import PropTypes from "prop-types"
import { Link } from 'gatsby'
import { OutboundLink } from "gatsby-plugin-google-gtag"
const LinkComponent = class extends React.Component {
render() {
let { href, children, className, id, ...rest } = this.props;
if(href.match(/^(http:\/\/|https:\/\/|www\.)/)){
return (
<OutboundLink href={href} id={id} className={className} target="_blank" rel="noopener noreferrer" {...rest}>
{children}
</OutboundLink>
)
} else if (href.match(/mailto:/)){
return (
<a href={href} id={id} className={className} {...rest}>
{children}
</a>
)
} else {
return (
<Link to={href} id={id} className={className} {...rest}>
{children}
</Link>
)
}
}
}
LinkComponent.propTypes = {
href: PropTypes.string.isRequired
}
export default LinkComponent