fix(link): internal link bug

This commit is contained in:
2021-02-02 11:26:09 +00:00
parent 31add6b9ef
commit c25f931cd1

View File

@@ -18,9 +18,15 @@ const StyledLink = styled.a`
`; `;
export default function Link({ children, to, ...other }) { export default function Link({ children, to, ...other }) {
const isInternal = /^\/(?!\/)/.test(to); if (/^\/(?!\/)/.test(to)) {
return (
<StyledLink to={to} as={GatsbyLink} {...other}>
{children}
</StyledLink>
);
}
return ( return (
<StyledLink href={to} as={isInternal ? GatsbyLink : "a"} {...other}> <StyledLink href={to} {...other}>
{children} {children}
</StyledLink> </StyledLink>
); );