nextjs 13 应用程序路由器生成元数据不适用于带有中文单词香港的 href

问题描述 投票:0回答:1

我正在将页面路由器迁移到应用程序路由器,并且generateMetadata不适用于带有特殊字符(例如中文单词香港)的href

`

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, } } }
我想要/zh/巴基斯坦
但在链接中生成元数据,使用encodedURI /zh/%E5%B7%B4%E5%9F%BA%E6%96%AF%E5%9D%A6创建链接

我也尝试过decodeURI(巴基斯坦)但没用

next.js13 app-router hreflang
1个回答
0
投票
也许你可以尝试类似的事情

languagePaths[language] = decodeURI(path);
    
© www.soinside.com 2019 - 2024. All rights reserved.