This commit is contained in:
Linus Flood
2024-10-21 09:53:40 +02:00
parent 827417ba40
commit 09777ee909
3 changed files with 40 additions and 33 deletions

View File

@@ -5,6 +5,7 @@ import { startTransition, useCallback, useMemo } from "react"
import useRouterTransitionStore from "@/stores/router-transition"
import { useCheckIfExternalLink } from "@/hooks/useCheckIfExternalLink"
import { trackClick, trackPageViewStart } from "@/utils/tracking"
import { linkVariants } from "./variants"
@@ -55,6 +56,9 @@ export default function Link({
return `${href}${search}`
}, [href, searchParams, keepSearchParams])
// TODO: Remove this check (and hook) and only return <Link /> when current web is deleted
const isExternal = useCheckIfExternalLink(href)
const startRouterTransition = useRouterTransitionStore(
(state) => state.startRouterTransition
)
@@ -65,11 +69,17 @@ export default function Link({
}
}, [trackingId])
return (
const linkProps = {
href: fullUrl,
className: classNames,
}
return isExternal ? (
<a {...linkProps} {...props} />
) : (
<NextLink
scroll={scroll}
prefetch={prefetch}
className={classNames}
onClick={(e) => {
if (onClick) {
onClick(e)
@@ -94,9 +104,9 @@ export default function Link({
router.push(fullUrl, { scroll })
})
}}
href={fullUrl}
id={trackingId}
{...props}
{...linkProps}
/>
)
}