Muhammad Naeem
Muhammad Naeem

Reputation: 1

nextjs 13 app router generateMetadata not working for href with chinese word 香港

I am working on migration of pages router to app router and generateMetadata not working for href with special characters sucha as chinese word 香港

`

export async function generateMetadata({ params }) {
  const { data } = await getData(params);
  const languagePaths = {};
  {data?.countries?.data?.grumpeatCountries?.content?.map((country) => {
    country?.availableLanguages?.map((countryLanguage) => {
      const language = `${countryLanguage.languageCode}-${country.code}`;
      const path = `/${countryLanguage.languageCode}/${countryLanguage.countryName?.replace(/%20|\s/g, '_')}`
      languagePaths[language] = path;
    });
  })}
  return {
    metadataBase: new URL('https://www.grumpeat.com'),
    alternates: {
      canonical: '/',
      languages: languagePaths,
    }
  }
}

i want /zh/巴基斯坦 but in link generate metadata creating link with encodedURI /zh/%E5%B7%B4%E5%9F%BA%E6%96%AF%E5%9D%A6

i also tried decodeURI(巴基斯坦) but not worked

Upvotes: 0

Views: 106

Answers (1)

WMS EPD HKSARG
WMS EPD HKSARG

Reputation: 1

Maybe you can try something like

languagePaths[language] = decodeURI(path);

Upvotes: 0

Related Questions