You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nuxt3中@nuxtjs/i18n的prefix_except_default策略失效求助

解决Nuxt3中@nuxtjs/i18n的prefix_except_default路由策略不生效问题

问题原因

@nuxtjs/i18n v8版本中,路由相关配置(比如prefix_except_default策略)需要放在nuxt.config.ts的i18n选项下,而非i18n.config.ts文件中。你当前把路由策略配置在了错误位置,导致策略无法生效。

修改步骤

1. 更新nuxt.config.ts

将路由策略、默认语言、支持的语言列表等配置移至此处:

export default defineNuxtConfig({
  modules: [
    '@nuxtjs/i18n'
  ],
  i18n: {
    strategy: 'prefix_except_default',
    defaultLocale: 'en',
    locales: [
      { code: 'en', name: 'English' },
      { code: 'ua', name: 'Ukrainian' }
    ]
  }
})

2. 调整i18n.config.ts

保留核心国际化配置,移除路由相关配置项:

export default defineI18nConfig(() => ({
  legacy: false,
  locale: 'en',
  messages: {
    en: {
      welcome: 'Welcome'
    },
    ua: {
      welcome: 'Ласкаво просимо'
    }
  }
}))

3. 验证

重启nuxt dev服务后,测试路由:

  • 英文默认路由:http://localhost:3000/
  • 乌克兰语路由:http://localhost:3000/ua

此时路由策略即可正常生效。


内容的提问来源于stack exchange,提问作者Oleksandr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 09:34:58