Skip to content

i18n - How I'm supposed to get the correct page linked to correct locale ? #1908

@Pamavoc

Description

@Pamavoc

Environment

Classic nuxt 3 project with this as nuxt.config :

modules: ["@nuxt/content", "@nuxtjs/i18n", '@nuxt/devtools'],
  content: {
    locales:[
      'en', 'fr'
    ],
    defaultLocale: 'fr'
  },
  i18n: { 
    strategy: 'prefix',
    defaultLocale: 'fr',
    baseUrl: process.env.BASE_URL || 'https://localhost:3000',
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'i18n_redirected',
      redirectOn: 'root',  // recommended
    },
    locales: [
      {
        code: 'en',
        iso: 'en-US'
      },
      {
        code: 'fr',
        iso: 'fr-FR'
      }
    ]
  }

This is the content folder :
image

Reproduction

Use a catchall page [...slug].vue in the pages directory with the same structure as me & same nuxt config

Try to fetch all pages :

const data = await queryContent().where({ _locale: locale.value }).find() 
console.log(data)

You'll get this :
image

But when you will use :

const { path } = useRoute()
const { locale } = useI18n()
const data = await queryContent().where({ _locale: locale.value, _path: path }).findOne()
console.log(data)

You will normally get this :
image

Describe the bug

where query parameter is maybe broken with multi lang. It won't fetch the correct page but will fetch correctly multiples pages in the folder.

I believe it is not linked to the module i18n.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions