Skip to content

Commit

Permalink
Merge pull request #1083 from basedosdados/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
AldemirLucas authored Dec 12, 2024
2 parents 6382850 + 7caf7cb commit 2480477
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion next/components/atoms/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ export default function Link({
}) {
const { locale } = useRouter();

const isExternalLink = (() => {
try {
const linkUrl = new URL(href, window.location.origin);
return linkUrl.origin !== window.location.origin;
} catch (error) {
return false;
}
})();

if (isExternalLink) {
return (
<Text
as="a"
href={href}
target={target || "_blank"}
rel="noopener noreferrer"
display="flex"
flexDirection="row"
alignItems="center"
fontFamily="Roboto"
cursor="pointer"
fontSize="14px"
lineHeight="20px"
fontWeight={fontWeight}
color={color}
{...props}
>
{children}
</Text>
);
}

return (
<NextLink href={href || '#'} locale={locale} passHref legacyBehavior>
<Text
Expand All @@ -33,4 +65,3 @@ export default function Link({
</NextLink>
);
}

0 comments on commit 2480477

Please sign in to comment.