fix(SW-2754): Fixed issue where server rendered html included faulty links

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-05-16 06:21:09 +00:00
parent 4f8483305d
commit 2401615caa
12 changed files with 67 additions and 78 deletions

View File

@@ -1,8 +1,7 @@
"use client"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { type ComponentProps, type PropsWithChildren, useMemo } from "react"
import { type ComponentProps, type PropsWithChildren } from "react"
import { trackClick } from "@/utils/tracking"
@@ -16,7 +15,6 @@ export interface ButtonLinkProps
VariantProps<typeof variants> {
trackingId?: string
trackingParams?: Record<string, string>
appendToCurrentPath?: boolean
}
export default function ButtonLink({
@@ -31,10 +29,8 @@ export default function ButtonLink({
onClick = () => {},
trackingId,
trackingParams,
appendToCurrentPath,
...props
}: ButtonLinkProps) {
const currentPageSlug = usePathname()
const classNames = variants({
variant,
color,
@@ -44,19 +40,10 @@ export default function ButtonLink({
className,
})
const fullUrl = useMemo(() => {
let newPath = href
if (appendToCurrentPath) {
newPath = `${currentPageSlug}${newPath}`
}
return newPath
}, [href, appendToCurrentPath, currentPageSlug])
return (
<Link
className={classNames}
href={fullUrl}
href={href}
target={target}
onClick={(e) => {
onClick(e)