Skip to content

Commit 39cf310

Browse files
committed
feat: add isHash handling to Link component
1 parent 2107fe3 commit 39cf310

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/components/Link.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const BaseLink = forwardRef(function Link(
6767
const isPdf = url.isPdf(href)
6868
const isExternal = url.isExternal(href)
6969
const isInternalPdf = isPdf && !isExternal
70+
const isHash = url.isHash(href)
7071

7172
// Get proper download link for internally hosted PDF's & static files (ex: whitepaper)
7273
// Opens in separate window.
@@ -119,6 +120,27 @@ export const BaseLink = forwardRef(function Link(
119120
)
120121
}
121122

123+
if (isHash) {
124+
return (
125+
<ChakraLink
126+
onClick={(e) => {
127+
e.stopPropagation()
128+
trackCustomEvent(
129+
customEventOptions ?? {
130+
eventCategory: "Link",
131+
eventAction: "Clicked",
132+
eventName: "Clicked on hash link",
133+
eventValue: href,
134+
}
135+
)
136+
}}
137+
{...commonProps}
138+
>
139+
{children}
140+
</ChakraLink>
141+
)
142+
}
143+
122144
return (
123145
<NextLink
124146
locale={locale}

src/lib/utils/url.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ export const isHrefActive = (
3333
? pathname.startsWith(cleanHref)
3434
: pathname === cleanHref
3535
}
36+
37+
export const isHash = (href: string): boolean => href.startsWith("#")

0 commit comments

Comments
 (0)