Commit a34dc73c authored by Moody Salem's avatar Moody Salem

Don't always redirect for links

parent 07fee045
...@@ -58,29 +58,38 @@ const StyledLink = styled.a` ...@@ -58,29 +58,38 @@ const StyledLink = styled.a`
} }
` `
// eslint-disable-next-line @typescript-eslint/no-unused-vars export function Link({
export function Link({ onClick, as, ref, target, href, rel, ...rest }: HTMLProps<HTMLAnchorElement>) { onClick,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
as,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ref,
target = '_blank',
href,
rel = 'noopener noreferrer',
...rest
}: HTMLProps<HTMLAnchorElement>) {
const handleClick = useCallback( const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => { (event: React.MouseEvent<HTMLAnchorElement>) => {
onClick && onClick(event) // first call back into the original onClick onClick && onClick(event) // first call back into the original onClick
if (!href) return if (!href) return
// don't prevent default, don't redirect
if (target === '_blank') {
ReactGA.outboundLink({ label: href }, () => {
console.debug('Fired outbound link event', href)
})
} else {
event.preventDefault() event.preventDefault()
// send a ReactGA event and then trigger a location change // send a ReactGA event and then trigger a location change
ReactGA.outboundLink({ label: href }, () => { ReactGA.outboundLink({ label: href }, () => {
window.location.href = href window.location.href = href
}) })
}
}, },
[href, onClick] [href, onClick, target]
)
return (
<StyledLink
target={target ?? '_blank'}
rel={rel ?? 'noopener noreferrer'}
href={href}
onClick={handleClick}
{...rest}
/>
) )
return <StyledLink target={target} rel={rel} href={href} onClick={handleClick} {...rest} />
} }
const rotate = keyframes` const rotate = keyframes`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment