【问题标题】:How to manage i18n routing in next.js to use slash instead of dash如何在 next.js 中管理 i18n 路由以使用斜杠而不是破折号
【发布时间】:2022-01-06 11:39:58
【问题描述】:

我有一个包含多个国家/地区的网站,每个国家/地区都有多个区域设置 这是我的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 我想知道是否有可能实现?

【问题讨论】:

    标签: next.js i18next next-i18next


    【解决方案1】:

    您可以使用next.config.js 中的rewrites 将所需的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
            ]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2011-08-08
      相关资源
      最近更新 更多