fix(SW-2754): Fixed issue where server rendered html included faulty links
Approved-by: Matilda Landström
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user