Next.js Discord

Discord Forum

SEO Problems i18n app router

Unanswered
Great black wasp posted this in #help-forum
Open in Discord
Great black waspOP
Google is not indexing my homepage. It has two language versions (en and es) and I am using Next Js with the app router setup. I followed the official guide of nextjs.
Nextjs app router creates a redirect from https://www.aquicreative.com to https://www.aquicreative.com/en (or /es if the Spanish locale is set).
The guide says to add a canonical for the root page and not including the /en, in my case: https://www.aquicreative.com, and have two alternate hreflang links for url including the locale. I currently have this setup and I get an error in search console: “Alternative page with proper canonical tag” for https://www.aquicreative.com/en so the main homepage in my default language cannot be indexed.
So I tried changing the canonical to include the locale: https://www.aquicreative.com/en and https://www.aquicreative.com/es using the dynamic locale from params. I expected this to recognise the current locale as the correct version of the site for that locale.
But I get a different error:
"Duplicate, Google chose different canonical than user"
So what should I do? Is it possible to get homepage indexed with app router using i18n? Or do I have to rebuild using the pages router again.

1 Reply

Great black waspOP
Here is the GenerateMetaData function on app/[lang]/page.tsx :

export async function generateMetadata({
  params: { lang },
}: {
  params: { lang: Locale };
}) {
  const t = await getDictionary(lang);
  return {
    metadataBase: new URL(
      process.env.SITE_URL ?? "https://www.aquicreative.com"
    ),
    alternates: {
      canonical: `/`,
      languages: {
        en: "/en",
        es: "/es",
      },
    },
    title: `${t.home.seo_title}`,
    description: `${t.home.seo_description}`,
  };
}