Domain routing for locales lets you serve different languages or regions from different domains or subdomains automatically based on the user's locale.
Click to reveal answer
beginner
How do you configure domain routing for locales in Next.js?
You add a 'domains' array inside the 'i18n' config in next.config.js. Each domain object specifies the domain name and the defaultLocale it serves.
Click to reveal answer
intermediate
Example of a domain configuration for French locale on 'example.fr'?
In next.config.js: { domains: [{ domain: 'example.fr', defaultLocale: 'fr' }] } inside the i18n config.
Click to reveal answer
intermediate
What happens if a user visits a domain not listed in the domain routing config?
Next.js falls back to the default locale and domain specified in the i18n config or redirects based on your setup.
Click to reveal answer
intermediate
Why use domain routing for locales instead of path-based locale routing?
Domain routing provides a cleaner URL without locale prefixes and can improve SEO by targeting specific country domains.
Click to reveal answer
Where do you configure domain routing for locales in Next.js?
Apublic folder
Bpages/_app.js
Cnext-env.d.ts
Dnext.config.js inside the i18n object
✗ Incorrect
Domain routing for locales is set inside the i18n configuration in next.config.js.
What key do you use to specify the domain for a locale in Next.js config?
AlocaleDomain
Bdomain
Chost
Dsite
✗ Incorrect
The key 'domain' specifies the domain name for a locale in the domains array.
If you want 'example.de' to serve German content, how do you specify it?
A{ domain: 'example.de', defaultLocale: 'de' }
B{ domain: 'de.example.com', locale: 'de' }
C{ host: 'example.de', locale: 'de' }
D{ domain: 'example.de', locale: 'en' }
✗ Incorrect
You specify the domain and defaultLocale like { domain: 'example.de', defaultLocale: 'de' }.
What benefit does domain routing provide over path-based locale routing?
AShorter URLs without locale prefixes
BSlower page loads
CRequires no configuration
DWorks only on localhost
✗ Incorrect
Domain routing gives cleaner URLs without locale prefixes like /en or /fr.
What happens if a user visits a domain not configured for any locale?
AThe site crashes
BUser is redirected to Google
CNext.js uses the default locale
DThe page shows a 404 error
✗ Incorrect
Next.js falls back to the default locale if the domain is not configured.
Explain how to set up domain routing for locales in a Next.js project.
Think about where Next.js config lives and how locales are defined.
You got /4 concepts.
Describe the advantages of using domain routing for locales compared to path-based locale routing.
Consider URL appearance and search engine benefits.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of domain routing for locales in Next.js?
easy
A. To enable client-side routing only
B. To improve server performance by caching
C. To create multiple apps in one project
D. To serve different languages on different domains
Solution
Step 1: Understand domain routing concept
Domain routing allows serving different languages or locales on separate domains or subdomains.
Step 2: Identify the main use case in Next.js
Next.js uses domain routing to link domains to specific locales for internationalization.
Final Answer:
To serve different languages on different domains -> Option D
Quick Check:
Domain routing = serve languages on domains [OK]
Hint: Domain routing connects domains to languages [OK]
Common Mistakes:
Confusing domain routing with caching
Thinking it only affects client-side routing
Assuming it creates multiple apps
2. Which Next.js config property is used to define domain routing for locales?
easy
A. routing.locales
B. i18n.domains
C. locales.domains
D. next.config.domains
Solution
Step 1: Recall Next.js i18n config structure
The internationalization config uses the i18n key in next.config.js.
Step 2: Identify the property for domain routing
The correct property to define domain-locale mapping is i18n.domains.
Final Answer:
i18n.domains -> Option B
Quick Check:
Domain routing config = i18n.domains [OK]
Hint: Look inside i18n config for domains key [OK]
Common Mistakes:
Using next.config.domains instead of i18n.domains
Confusing with routing.locales
Trying to set domains outside i18n
3. Given this Next.js i18n config snippet, what locale will be served for requests to https://example.fr?
A. Rewriting to '/fr' instead of setting locale cookie
B. Not returning a response for all domains
C. Using 'host' header instead of 'x-forwarded-host'
D. Middleware missing 'export default'
Solution
Step 1: Understand middleware role in locale detection
Middleware should set locale or rewrite URL to include locale prefix properly.
Step 2: Identify issue with rewriting only
Rewriting to '/fr' alone may not set locale context; locale cookie or header is needed for Next.js to recognize locale.
Final Answer:
Rewriting to '/fr' instead of setting locale cookie -> Option A
Quick Check:
Middleware must set locale, not just rewrite URL [OK]
Hint: Middleware must set locale, not just rewrite URL [OK]
Common Mistakes:
Assuming host header is wrong
Forgetting to handle all domains
Missing export default in middleware
5. How would you configure Next.js to serve English on 'example.com' and French on 'example.fr' using domain routing, ensuring the default locale is English and URLs do not show locale prefixes?
hard
A. Set i18n.locales to ['en', 'fr'], defaultLocale to 'en', and i18n.domains with domains for example.com (fr) and example.fr (en), and use localeDetection: true
B. Set i18n.locales to ['en', 'fr'], defaultLocale to 'fr', and i18n.domains with domains for example.com (fr) and example.fr (en), and use localeDetection: true
C. Set i18n.locales to ['en', 'fr'], defaultLocale to 'en', and i18n.domains with domains for example.com (en) and example.fr (fr), and use localeDetection: false
D. Set i18n.locales to ['en', 'fr'], defaultLocale to 'en', and no domains, rely on middleware only
Solution
Step 1: Define locales and defaultLocale correctly
Locales should be ['en', 'fr'] with defaultLocale 'en' to serve English by default.
Step 2: Configure i18n.domains for domain-locale mapping
Map 'example.com' to 'en' and 'example.fr' to 'fr' in i18n.domains array.
Step 3: Disable localeDetection to avoid prefix in URLs
Setting localeDetection: false prevents Next.js from adding locale prefixes in URLs, serving clean domain-based locales.
Final Answer:
Set i18n.locales to ['en', 'fr'], defaultLocale to 'en', and i18n.domains with domains for example.com (en) and example.fr (fr), and use localeDetection: false -> Option C
Quick Check:
Domain routing + defaultLocale + no prefix = Set i18n.locales to ['en', 'fr'], defaultLocale to 'en', and i18n.domains with domains for example.com (en) and example.fr (fr), and use localeDetection: false [OK]
Hint: Use i18n.domains and disable localeDetection for clean URLs [OK]
Common Mistakes:
Swapping locales for domains
Forgetting to disable localeDetection
Relying only on middleware without domains
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.