0
0
NextJSframework~20 mins

Sub-path routing for locales in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Locale Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the rendered URL path for the French locale?
Given a Next.js app configured with sub-path routing for locales, if the user selects French (fr) locale, what will be the URL path for the home page?
NextJS
export const nextConfig = {
  i18n: {
    locales: ['en', 'fr', 'es'],
    defaultLocale: 'en',
    localeDetection: true
  }
};

// User navigates to home page with locale 'fr'
A/home/fr
B/en/fr
C/?locale=fr
D/fr
Attempts:
2 left
💡 Hint
Think about how Next.js adds locale prefixes as sub-paths by default.
📝 Syntax
intermediate
1:30remaining
Which Next.js config correctly enables sub-path routing for locales?
Select the Next.js configuration snippet that correctly enables sub-path routing for English and Spanish locales with English as default.
A
module.exports = {
  i18n: {
    locales: ['en', 'es'],
    defaultLocale: 'en',
    localeDetection: false
  }
};
B
module.exports = {
  i18n: {
    locales: ['en', 'es'],
    defaultLocale: 'es',
    localeDetection: true
  }
};
C
module.exports = {
  i18n: {
    locales: ['en', 'es'],
    defaultLocale: 'en',
    subPathRouting: true
  }
};
D
module.exports = {
  i18n: {
    locales: ['en', 'es'],
    defaultLocale: 'en'
  },
  localeRouting: 'subpath'
};
Attempts:
2 left
💡 Hint
Check the official Next.js i18n config options for sub-path routing.
state_output
advanced
1:30remaining
What locale is active after navigating to /es/about?
In a Next.js app with locales ['en', 'es', 'fr'] and defaultLocale 'en', if the user visits the URL path '/es/about', what is the active locale in the app?
Afr
Ben
Ces
Dundefined
Attempts:
2 left
💡 Hint
The locale is determined by the first segment of the URL path when using sub-path routing.
🔧 Debug
advanced
2:00remaining
Why does the locale sub-path not appear in URLs?
A developer configures Next.js with locales ['en', 'fr'] and defaultLocale 'en'. However, when navigating, URLs do not show '/fr' prefix for French locale. What is the most likely cause?
NextJS
module.exports = {
  i18n: {
    locales: ['en', 'fr'],
    defaultLocale: 'en',
    localeDetection: true
  },
  trailingSlash: true
};
AThe developer forgot to set the 'locale' property in next.config.js
BThe developer is using 'defaultLocale' as 'en', so URLs for 'en' do not get a prefix, but French URLs should have '/fr'
CThe developer is using 'localeDetection: true' which disables sub-path routing
DThe app is running in development mode which disables locale sub-paths
Attempts:
2 left
💡 Hint
Remember how Next.js handles defaultLocale URLs.
🧠 Conceptual
expert
2:30remaining
How does Next.js handle locale sub-path routing with middleware?
In Next.js, when using middleware to rewrite URLs for locale sub-path routing, what is the primary purpose of the middleware?
ATo detect user locale and redirect to the correct locale sub-path before rendering
BTo disable locale sub-path routing and serve all locales under root path
CTo statically generate pages for each locale at build time
DTo inject locale-specific CSS styles dynamically
Attempts:
2 left
💡 Hint
Middleware runs before the request reaches the page and can modify the request or response.