Newer
Older
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
49
50
51
52
53
// From https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/
import { Link as GatsbyLink } from "gatsby";
interface Props {
children?: React.ReactNode;
to: string;
activeClassName?: string;
partiallyActive?: string;
}
// Since DOM elements <a> cannot receive activeClassName
// and partiallyActive, destructure the prop here and
// pass it only to GatsbyLink
const Link = ({
children,
to,
activeClassName,
partiallyActive,
...other
}: Props) => {
// Si commence par http
// Si contient
// geoportal | geonetwork | metabase | ...
// Basé sur les données de l'api grapgql = liste des pages ?
// 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 (
<GatsbyLink
to={to}
activeClassName={activeClassName}
partiallyActive={partiallyActive}
{...other}
>
{children}
</GatsbyLink>
);
}
return (
<a href={to} {...other}>
{children}
</a>
);
};
export default Link;