next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Router: defaultLocale and locale are swapped

Open fmacherey opened this issue 5 years ago • 3 comments

What version of Next.js are you using?

10.0.9

What version of Node.js are you using?

15.5.1

What browser are you using?

Chromium

What operating system are you using?

macOS

How are you deploying your application?

Other

Describe the Bug

We are using domain routing with subdomains to localize our app. I configured three domains with locales in next.config.js:

    domains = [
        {
            domain: "www.example.com",
            defaultLocale: "de-DE",
        },
        {
            domain: "at.example.com",
            defaultLocale: "de-AT",
        },
        {
            domain: "ch.example.com",
            defaultLocale: "de-CH",
        },
    ];

The default locale is set to de-DE I set the domains depending on which env to deploy (local, stage, prod). For localhost, everything works as it expected. When deploying to our stage, the non-defaults aren't working. When logging the whole object returned from useRouter, I figured out, that defaultLocale and locale props seems to be swapped.

I also switched off automatic locale detection, so that only the url should be affect the locale.

We are using next with current [email protected]

Expected Behavior

router.defaultLocale is always "de-DE" (in our case) and router.locale is the locale, depending on domain setting.

To Reproduce

see above

fmacherey avatar Mar 19 '21 13:03 fmacherey

I also left a comment here, as it is maybe related https://github.com/vercel/next.js/issues/21810#issuecomment-797412757

fmacherey avatar Mar 19 '21 13:03 fmacherey

We are facing the similar issue with [email protected]

Did you find out any workaround? @fmacherey

fatihpkn avatar Oct 23 '22 14:10 fatihpkn

We figure out this issue. In our case nginx doesn't pass host header to server, so we pass the host and it works normally now

fatihpkn avatar Nov 08 '22 10:11 fatihpkn