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:
@@ -88,7 +88,7 @@ export default async function SolutionPage({ params }: PageProps) {
|
||||
// Filter out bundle products (2x, 3x versions) - only show original 4 products
|
||||
const products = filterOutBundles(allProducts).slice(0, 4);
|
||||
|
||||
const basePath = validLocale === DEFAULT_LOCALE ? "" : `/${validLocale}`;
|
||||
const basePath = `/${validLocale}`;
|
||||
|
||||
const faqQuestions = page.faqs.map((faq) => ({
|
||||
question: getLocalizedString(faq.question, validLocale),
|
||||
|
||||
@@ -26,7 +26,7 @@ export function OilForConcernPageTemplate({ page, locale, basePath, products }:
|
||||
const howToApply = getLocalizedArray(page.howToApply, locale);
|
||||
const expectedResults = getLocalizedString(page.expectedResults, locale);
|
||||
const timeframe = getLocalizedString(page.timeframe, locale);
|
||||
const productsHref = locale === "sr" ? "/products" : `/${locale}/products`;
|
||||
const productsHref = `${basePath}/products`;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -149,7 +149,7 @@ export function OilForConcernPageTemplate({ page, locale, basePath, products }:
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<ProductsGrid products={products} locale={locale} />
|
||||
<ProductsGrid products={products} locale={locale} basePath={basePath} />
|
||||
</main>
|
||||
<Footer locale={locale} />
|
||||
</>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user