-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathLink.jsx
More file actions
48 lines (44 loc) · 1.2 KB
/
Link.jsx
File metadata and controls
48 lines (44 loc) · 1.2 KB
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
38
39
40
41
42
43
44
45
46
47
48
import React from "react";
import { Link as InternalLink } from "gatsby";
import { FaExternalLinkAlt } from "react-icons/fa";
// See https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/#reminder-use-link-only-for-internal-links
// Since DOM elements <a> cannot receive activeClassName
// and partiallyActive, destructure the prop here and
// pass it only to GatsbyLink
function Link({
children,
to,
activeClassName,
partiallyActive,
Indicator = FaExternalLinkAlt,
...other
}) {
// Tailor the following test to your environment.
// This example assumes that any internal link (intended for Gatsby)
// will start with exactly one slash, and that anything else is external.
const internal = /^\/(?!\/)/.test(to);
// Use Gatsby Link for internal links, and <a> for others
if (internal) {
return (
<InternalLink
to={to}
activeClassName={activeClassName}
partiallyActive={partiallyActive}
{...other}
>
{children}
</InternalLink>
);
}
return (
<a href={to} {...other}>
{children}
<Indicator
style={{
marginLeft: "0.5rem",
}}
/>
</a>
);
}
export default Link;