Skip to content
Snippets Groups Projects
Link.tsx 1.55 KiB
Newer Older
// From https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/

import React from "react"
Toavina's avatar
Toavina committed
import { Link as GatsbyLink } from "gatsby"
interface Props {
Toavina's avatar
Toavina committed
    children?: React.ReactNode
    to: string
    activeClassName?: string
    partiallyActive?: any
    onClick?:any
    className?: any
}

// Since DOM elements <a> cannot receive activeClassName
// and partiallyActive, destructure the prop here and
// pass it only to GatsbyLink
const Link = ({
Toavina's avatar
Toavina committed
    children,
    to,
    activeClassName,
    partiallyActive,
    onClick,
    className,
Toavina's avatar
Toavina committed
    ...other
Toavina's avatar
Toavina committed
    // Si commence par http
    // Si contient
    //    geoportal | geonetwork | metabase | ...
Toavina's avatar
Toavina committed
    // Basé sur les données de l'api grapgql = liste des pages ?
Toavina's avatar
Toavina committed
    // 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)
Toavina's avatar
Toavina committed
    // Use Gatsby Link for internal links, and <a> for others
    if (internal) {
        return (
            <GatsbyLink
                to={to}
                activeClassName={activeClassName}
                partiallyActive={partiallyActive}
                onClick={onClick}
                className = {className}
Toavina's avatar
Toavina committed
                {...other}
            >
                {children}
            </GatsbyLink>
        )
    }
        <a href={to} {...other} onClick={onClick} className = {className}>
Toavina's avatar
Toavina committed
            {children}
        </a>
    )
}
Toavina's avatar
Toavina committed
export default Link