You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: When using domain-based routing, use defaultLocale of a domain instead of the top-level one in case no other locale matches better on the domain (#1000)
Fixes#998
Note that the `defaultLocale` of a domain is used if no other locale
matches better. However, if a domain supports multiple locales, the
best-matching one will be selected based on the `accept-language`
header. If you want to always use the `defaultLocale` in case no prefix
is provided, then you can turn off `localeDetection`.
// Optionally restrict the locales managed by this domain. If this
88
-
// domain receives requests for another locale (e.g. us.example.com/fr),
89
-
// then the middleware will redirect to a domain that supports it.
87
+
// Optionally restrict the locales available on this domain
90
88
locales: ['en']
91
89
},
92
90
{
93
91
domain: 'ca.example.com',
94
92
defaultLocale: 'en'
95
93
// If there are no `locales` specified on a domain,
96
-
// all global locales will be supported here.
94
+
// all available locales will be supported here
97
95
}
98
96
]
99
97
});
@@ -110,11 +108,12 @@ To match the request against the available domains, the host is read from the `x
110
108
111
109
The locale is detected based on these priorities:
112
110
113
-
1. A locale prefix is present in the pathname and the domain supports it (e.g. `ca.example.com/fr`)
114
-
2. If the host of the request is configured in `domains`, the `defaultLocale` of the domain is used
115
-
3. As a fallback, the [locale detection of prefix-based routing](#locale-detection) applies
111
+
1. A locale prefix is present in the pathname (e.g. `ca.example.com/fr`)
112
+
2. A locale is stored in a cookie and is supported on the domain
113
+
3. A locale that the domain supports is matched based on the [`accept-language` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)
114
+
4. As a fallback, the `defaultLocale` of the domain is used
116
115
117
-
Since the middleware is aware of all your domains, the domain will automatically be switched when the user requests to change the locale.
116
+
Since the middleware is aware of all your domains, if a domain receives a request for a locale that is not supported (e.g. `en.example.com/fr`), it will redirect to an alternative domain that does support the locale.
0 commit comments