fix: ensure all links are properly localized with locale prefix

- Update basePath to always include locale prefix (/)
- Fix productsHref to use basePath consistently
- Fix product links in ProductsGrid to use basePath
- Ensure /sr/pages link to /sr/products, /en to /en/products, etc.
This commit is contained in:
Unchained
2026-04-09 10:03:26 +02:00
parent 9ab07ab01d
commit 04d8d773bf
3 changed files with 8 additions and 6 deletions
@@ -14,9 +14,10 @@ import Link from "next/link";
interface ProductsGridProps {
products: Product[];
locale: string;
basePath?: string;
}
function ProductCardWithAddToCart({ product, index, locale }: { product: Product; index: number; locale: string }) {
function ProductCardWithAddToCart({ product, index, locale, basePath = "" }: { product: Product; index: number; locale: string; basePath?: string }) {
const t = useTranslations("ProductCard");
const tProduct = useTranslations("Product");
const [isAdding, setIsAdding] = useState(false);
@@ -29,7 +30,7 @@ function ProductCardWithAddToCart({ product, index, locale }: { product: Product
const localized = getLocalizedProduct(product, saleorLocale);
const variant = product.variants?.[0];
const isAvailable = (variant?.quantityAvailable || 0) > 0;
const productHref = locale === "sr" ? `/products/${localized.slug}` : `/${locale}/products/${localized.slug}`;
const productHref = `${basePath}/products/${localized.slug}`;
const handleAddToCart = async (e: React.MouseEvent) => {
e.preventDefault();
@@ -127,7 +128,7 @@ function ProductCardWithAddToCart({ product, index, locale }: { product: Product
);
}
export default function ProductsGrid({ products, locale }: ProductsGridProps) {
export default function ProductsGrid({ products, locale, basePath = "" }: ProductsGridProps) {
const t = useTranslations("Solutions");
const validProducts = products.filter(p => p && p.id);
@@ -150,6 +151,7 @@ export default function ProductsGrid({ products, locale }: ProductsGridProps) {
product={product}
index={index}
locale={locale}
basePath={basePath}
/>
))}
</div>