mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 14:42:31 +00:00
Update variant-selector.tsx (#1115)
This commit is contained in:
parent
586f9bfe56
commit
7dc7e6d6e4
@ -4,7 +4,7 @@ import clsx from 'clsx';
|
||||
import { ProductOption, ProductVariant } from 'lib/shopify/types';
|
||||
import { createUrl } from 'lib/utils';
|
||||
import Link from 'next/link';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { redirect, usePathname, useSearchParams } from 'next/navigation';
|
||||
|
||||
type ParamsMap = {
|
||||
[key: string]: string; // ie. { color: 'Red', size: 'Large', ... }
|
||||
@ -26,7 +26,6 @@ export function VariantSelector({
|
||||
}) {
|
||||
const pathname = usePathname();
|
||||
const currentParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const hasNoOptionsOrJustOneOption =
|
||||
!options.length || (options.length === 1 && options[0]?.values.length === 1);
|
||||
|
||||
@ -80,7 +79,7 @@ export function VariantSelector({
|
||||
const selectedVariantUrl = createUrl(pathname, selectedVariantParams);
|
||||
|
||||
if (currentUrl !== selectedVariantUrl) {
|
||||
router.replace(selectedVariantUrl);
|
||||
redirect(selectedVariantUrl);
|
||||
}
|
||||
|
||||
return options.map((option) => (
|
||||
|
Loading…
x
Reference in New Issue
Block a user