fix: pass onclick prop to next link
This commit is contained in:
@@ -23,6 +23,7 @@ export default function Link({
|
||||
prefetch,
|
||||
variant,
|
||||
trackingId,
|
||||
onClick,
|
||||
...props
|
||||
}: LinkProps) {
|
||||
const currentPageSlug = usePathname()
|
||||
@@ -53,26 +54,21 @@ export default function Link({
|
||||
}
|
||||
}, [trackingId])
|
||||
|
||||
useEffect(() => {
|
||||
if (trackingId) {
|
||||
const linkComponent = document.getElementById(trackingId)
|
||||
|
||||
linkComponent?.addEventListener("click", trackClickById)
|
||||
return () => {
|
||||
linkComponent?.removeEventListener("click", trackClickById)
|
||||
}
|
||||
}
|
||||
}, [trackClickById, trackingId])
|
||||
|
||||
return (
|
||||
<NextLink
|
||||
scroll={scroll}
|
||||
prefetch={prefetch}
|
||||
className={classNames}
|
||||
onClick={() => {
|
||||
onClick={(e) => {
|
||||
trackPageViewStart()
|
||||
startTransition(() => {
|
||||
startRouterTransition()
|
||||
if (trackingId) {
|
||||
trackClickById()
|
||||
}
|
||||
if (onClick) {
|
||||
onClick(e)
|
||||
}
|
||||
router.push(href)
|
||||
})
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user