2

我有一个包含多个国家/地区的网站,每个国家/地区都有多个地区,这是我的next-i18next.config.js

module.exports = {
  i18n: {
    defaultLocale: 'en-eg',
    locales: ['en-br', 'en-eg', 'en-ke', 'pt-br', 'pt-eg', 'pt-ke', 'en', 'pt'],
    localeDetection: false,
  },
  lowerCaseLng: true,
  fallbackLng: {
    'en-br': ['en'],
    'en-eg': ['en'],
    'en-ke': ['en'],
    'pt-br': ['pt'],
    'pt-eg': ['pt'],
    'pt-ke': ['pt'],
  },
};

想要的行为而不是/{language}-{country}/:path{country}/{language/:path想知道是否有可能实现?

4

1 回答 1

1

您可以使用rewritesinnext.config.js将所需的 URL 格式映射到实际存在的不同目标路径。

//next.config.js

module.exports = {
    async rewrites() {
        return [
            // Add an entry for each locale that needs to be mapped
            {
                source: '/br/pt/:path*',
                destination: '/pt-br/:path*'
            },
            // Other locales rewrites here
        ]
    }
}
于 2021-11-29T17:42:32.930 回答