From 57bae7ed6f735352f179921331b46c3ffd856fe0 Mon Sep 17 00:00:00 2001 From: Unchained Date: Mon, 6 Apr 2026 15:32:24 +0200 Subject: [PATCH] fix: canonical URLs to always include locale prefix Fixed Canonical Redirect Error in Google Search Console by ensuring canonical URLs always include the locale prefix (/sr, /en, /de, /fr) instead of omitting it for the default locale. Changes: - layout.tsx: Fixed canonical and hreflang URL generation - page.tsx: Fixed homepage canonical URL - contact/page.tsx: Fixed contact page canonical URL - about/page.tsx: Fixed about page canonical URL - products/page.tsx: Fixed products page canonical URL - products/[slug]/page.tsx: Fixed product detail canonical URL Before: /contact (when locale=sr) After: /sr/contact (all locales) Fixes: Canonical Redirect Error in Google Search Console --- src/app/[locale]/about/page.tsx | 2 +- src/app/[locale]/contact/page.tsx | 2 +- src/app/[locale]/layout.tsx | 4 ++-- src/app/[locale]/page.tsx | 4 ++-- src/app/[locale]/products/[slug]/page.tsx | 2 +- src/app/[locale]/products/page.tsx | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/[locale]/about/page.tsx b/src/app/[locale]/about/page.tsx index 14f4f84..9b97d33 100644 --- a/src/app/[locale]/about/page.tsx +++ b/src/app/[locale]/about/page.tsx @@ -19,7 +19,7 @@ export async function generateMetadata({ params }: AboutPageProps): Promise { const { locale } = await params; const validLocale = isValidLocale(locale) ? locale : DEFAULT_LOCALE; - const localePrefix = validLocale === DEFAULT_LOCALE ? "" : `/${locale}`; + const localePrefix = `/${locale}`; const languages: Record = {}; for (const loc of SUPPORTED_LOCALES) { - const prefix = loc === DEFAULT_LOCALE ? "" : `/${loc}`; + const prefix = `/${loc}`; languages[loc] = `${baseUrl}${prefix}`; } diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx index 7dc6ff0..a9b43bb 100644 --- a/src/app/[locale]/page.tsx +++ b/src/app/[locale]/page.tsx @@ -29,8 +29,8 @@ export async function generateMetadata({ params }: { params: Promise<{ locale: s setRequestLocale(validLocale); // Build canonical URL - const localePrefix = validLocale === DEFAULT_LOCALE ? "" : `/${validLocale}`; - const canonicalUrl = `${baseUrl}${localePrefix || '/'}`; + const localePrefix = `/${validLocale}`; + const canonicalUrl = `${baseUrl}${localePrefix}`; return { title: metadata.home.title, diff --git a/src/app/[locale]/products/[slug]/page.tsx b/src/app/[locale]/products/[slug]/page.tsx index c311135..b069183 100644 --- a/src/app/[locale]/products/[slug]/page.tsx +++ b/src/app/[locale]/products/[slug]/page.tsx @@ -57,7 +57,7 @@ export async function generateMetadata({ params }: ProductPageProps): Promise