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