【问题标题】:Nuxt.js: message: 'This page could not be found' (nuxt-i18n)Nuxt.js:消息:“找不到此页面”(nuxt-i18n)
【发布时间】:2019-03-03 05:02:59
【问题描述】:

在我的 Nuxt.js 应用程序中,我根据documentation 的建议安装了 nuxt-i18n

{
  modules: [
    ['nuxt-i18n', {
      // Options
    }]
  ]
}

但是当我运行 npm run dev 时,我收到以下错误消息:

 DONE  Compiled successfully in -4519ms                                12:53:52                                                                                         


 OPEN  http://localhost:3000                                                                                                                                            

  nuxt:render Rendering url / +0ms                                                                                                                                      
{ statusCode: 404,                                                                                                                                                      
  path: '/',                                                                                                                                                            
  message: 'This page could not be found' }  

如何解决这个问题?

【问题讨论】:

  • 你有pages/index.vue 文件吗?
  • 是的,默认情况下它在那里(我的意思是我没有对该文件进行任何更改)
  • 我在启用 nuxt-i18n 模块时重现您的问题。
  • 是的,确切地说,...我今天一直在努力解决这个问题

标签: javascript vue.js nuxt.js nuxt-i18n


【解决方案1】:

为了完成@Nicolas Pennec -great- answer,并且为了避免出现如下警告消息:Locale ISO code is required to generate alternate link,我们应该按照documentation 中的描述声明语言环境:

// nuxt.config.js

['nuxt-i18n', {
  locales: [
    {
      code: 'en',
      iso: 'en-US'
    },
    {
      code: 'es',
      iso: 'es-ES'
    },
    {
      code: 'fr',
      iso: 'fr-FR'
    }
  ]
}]

【讨论】:

    【解决方案2】:

    如果您设置默认语言环境,它会正常工作:)

      modules: [
        ['nuxt-i18n', {
          locales: ['en', 'fr', 'es'],
          defaultLocale: 'en',
          seo: false // workaround to fix the current issue on module https://github.com/nuxt-community/nuxt-i18n/issues/127
        }]
      ],
    

    【讨论】:

    • 非常聪明! ...并且使用 localesdefaultLocale 声明,我们不需要将 seo 设置为 false。非常感谢
    猜你喜欢
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2011-07-29
    • 2020-11-16
    • 2019-11-17
    • 2019-02-03
    • 1970-01-01
    相关资源
    最近更新 更多