Nuxt.js: message: 'This page could not be found' (nuxt-i18n)

谁说我不能喝 提交于 2019-12-11 16:57:30

问题


In my Nuxt.js application, I installed the nuxt-i18n according to how the documentation suggests:

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

But when I run npm run dev, I get this error message:

 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' }  

How to fix this?


回答1:


it works fine if you set a default locale :)

  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
    }]
  ],



回答2:


For the sake of completion to @Nicolas Pennec -great- answer, and in order to avoid warning messages as this one: Locale ISO code is required to generate alternate link, we should declare the locales as described in the documentation:

// nuxt.config.js

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


来源:https://stackoverflow.com/questions/52534308/nuxt-js-message-this-page-could-not-be-found-nuxt-i18n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!