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
|
// Filter out bundle products (2x, 3x versions) - only show original 4 products
|
||||||
const products = filterOutBundles(allProducts).slice(0, 4);
|
const products = filterOutBundles(allProducts).slice(0, 4);
|
||||||
|
|
||||||
const basePath = validLocale === DEFAULT_LOCALE ? "" : `/${validLocale}`;
|
const basePath = `/${validLocale}`;
|
||||||
|
|
||||||
const faqQuestions = page.faqs.map((faq) => ({
|
const faqQuestions = page.faqs.map((faq) => ({
|
||||||
question: getLocalizedString(faq.question, validLocale),
|
question: getLocalizedString(faq.question, validLocale),
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function OilForConcernPageTemplate({ page, locale, basePath, products }:
|
|||||||
const howToApply = getLocalizedArray(page.howToApply, locale);
|
const howToApply = getLocalizedArray(page.howToApply, locale);
|
||||||
const expectedResults = getLocalizedString(page.expectedResults, locale);
|
const expectedResults = getLocalizedString(page.expectedResults, locale);
|
||||||
const timeframe = getLocalizedString(page.timeframe, locale);
|
const timeframe = getLocalizedString(page.timeframe, locale);
|
||||||
const productsHref = locale === "sr" ? "/products" : `/${locale}/products`;
|
const productsHref = `${basePath}/products`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -149,7 +149,7 @@ export function OilForConcernPageTemplate({ page, locale, basePath, products }:
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<ProductsGrid products={products} locale={locale} />
|
<ProductsGrid products={products} locale={locale} basePath={basePath} />
|
||||||
</main>
|
</main>
|
||||||
<Footer locale={locale} />
|
<Footer locale={locale} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import Link from "next/link";
|
|||||||
interface ProductsGridProps {
|
interface ProductsGridProps {
|
||||||
products: Product[];
|
products: Product[];
|
||||||
locale: string;
|
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 t = useTranslations("ProductCard");
|
||||||
const tProduct = useTranslations("Product");
|
const tProduct = useTranslations("Product");
|
||||||
const [isAdding, setIsAdding] = useState(false);
|
const [isAdding, setIsAdding] = useState(false);
|
||||||
@@ -29,7 +30,7 @@ function ProductCardWithAddToCart({ product, index, locale }: { product: Product
|
|||||||
const localized = getLocalizedProduct(product, saleorLocale);
|
const localized = getLocalizedProduct(product, saleorLocale);
|
||||||
const variant = product.variants?.[0];
|
const variant = product.variants?.[0];
|
||||||
const isAvailable = (variant?.quantityAvailable || 0) > 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) => {
|
const handleAddToCart = async (e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
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 t = useTranslations("Solutions");
|
||||||
const validProducts = products.filter(p => p && p.id);
|
const validProducts = products.filter(p => p && p.id);
|
||||||
|
|
||||||
@@ -150,6 +151,7 @@ export default function ProductsGrid({ products, locale }: ProductsGridProps) {
|
|||||||
product={product}
|
product={product}
|
||||||
index={index}
|
index={index}
|
||||||
locale={locale}
|
locale={locale}
|
||||||
|
basePath={basePath}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user