diff --git a/components/product/variant-selector.tsx b/components/product/variant-selector.tsx index 3c25920acb..a35ca44cfe 100644 --- a/components/product/variant-selector.tsx +++ b/components/product/variant-selector.tsx @@ -6,8 +6,7 @@ import { VercelProductVariant as ProductVariant } from 'lib/bigcommerce/types'; import { createUrl } from 'lib/utils'; -import Link from 'next/link'; -import { usePathname, useSearchParams } from 'next/navigation'; +import { usePathname, useRouter, useSearchParams } from 'next/navigation'; type Combination = { id: string; @@ -22,6 +21,7 @@ export function VariantSelector({ options: ProductOption[]; variants: ProductVariant[]; }) { + const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const hasNoOptionsOrJustOneOption = @@ -79,17 +79,14 @@ export function VariantSelector({ // The option is active if it's in the url params. const isActive = searchParams.get(optionNameLowerCase) === value; - // You can't disable a link, so we need to render something that isn't clickable. - const DynamicTag = isAvailableForSale ? Link : 'p'; - const dynamicProps = { - ...(isAvailableForSale && { scroll: false }) - }; - return ( - { + router.replace(optionUrl, { scroll: false }); + }} title={`${option.name} ${value}${!isAvailableForSale ? ' (Out of Stock)' : ''}`} className={clsx( 'flex min-w-[48px] items-center justify-center rounded-full border bg-neutral-100 px-2 py-1 text-sm dark:border-neutral-800 dark:bg-neutral-900', @@ -101,10 +98,9 @@ export function VariantSelector({ !isAvailableForSale } )} - {...dynamicProps} > {value} - + ); })}