Merge branch 'develop' of bitbucket.org:scandic-swap/web into feature/tracking
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import NextLink from "next/link"
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
import { startTransition, useCallback } from "react"
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||
import { startTransition, useCallback, useMemo } from "react"
|
||||
|
||||
import { trackClick } from "@/utils/tracking"
|
||||
|
||||
@@ -22,9 +22,14 @@ export default function Link({
|
||||
variant,
|
||||
trackingId,
|
||||
onClick,
|
||||
/**
|
||||
* Decides if the link should include the current search params in the URL
|
||||
*/
|
||||
keepSearchParams,
|
||||
...props
|
||||
}: LinkProps) {
|
||||
const currentPageSlug = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
let isActive = active || currentPageSlug === href
|
||||
|
||||
if (partialMatch && !isActive) {
|
||||
@@ -42,6 +47,12 @@ export default function Link({
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const fullUrl = useMemo(() => {
|
||||
const search =
|
||||
keepSearchParams && searchParams.size ? `?${searchParams}` : ""
|
||||
return `${href}${search}`
|
||||
}, [href, searchParams, keepSearchParams])
|
||||
|
||||
const trackClickById = useCallback(() => {
|
||||
if (trackingId) {
|
||||
trackClick(trackingId)
|
||||
@@ -65,12 +76,17 @@ export default function Link({
|
||||
// track navigation nor start a router transition.
|
||||
return
|
||||
}
|
||||
if (href.startsWith("tel:") || href.startsWith("mailto:")) {
|
||||
// If href contains tel or mailto protocols we don't want to
|
||||
// track navigation nor start a router transition.
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
startTransition(() => {
|
||||
router.push(href, { scroll })
|
||||
router.push(fullUrl, { scroll })
|
||||
})
|
||||
}}
|
||||
href={href}
|
||||
href={fullUrl}
|
||||
id={trackingId}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user