Skip to content
Snippets Groups Projects
Commit 08cc84d2 authored by Julien MARGAIL's avatar Julien MARGAIL
Browse files

fix Link internal check

parent c8fe920c
No related branches found
No related tags found
No related merge requests found
// From https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/
import React from "react"
import { Link as GatsbyLink } from "gatsby"
import { graphql, useStaticQuery, Link as GatsbyLink } from "gatsby"
interface Props {
children?: React.ReactNode
to: string
activeClassName?: string
partiallyActive?: any
onClick?:any
onClick?: any
className?: any
}
......@@ -25,34 +24,44 @@ const Link = ({
className,
...other
}: Props) => {
// Si commence par http
// Si contient
// geoportal | geonetwork | metabase | ...
// Basé sur les données de l'api grapgql = liste des pages ?
// Basé sur les données de l'API GraphQL = liste des pages
const data = useStaticQuery(graphql`
query appPages {
allSitePage {
nodes {
path
}
}
}
`)
// 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)
// /^https?:\/\//
// Si "to" n'est pas dans la liste des pages, c'est un lien externe
// ignore le "/" à la fin du 'path' et de 'to'
const internal = data.allSitePage.nodes.find(
({ path }) => path.replace(/\/+$/, "") === to.replace(/\/+$/, "")
)
// Use Gatsby Link for internal links, and <a> for others
if (internal) {
// console.log("Internal", to)
return (
<GatsbyLink
to={to}
activeClassName={activeClassName}
partiallyActive={partiallyActive}
onClick={onClick}
className = {className}
className={className}
{...other}
>
{children}
</GatsbyLink>
)
}
// console.log("External", to)
return (
<a href={to} {...other} onClick={onClick} className = {className}>
<a href={to} {...other} onClick={onClick} className={className}>
{children}
</a>
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment