Sub-path routing for locales in Next.js
📖 Scenario: You are building a website that supports two languages: English and Spanish. You want users to see the language in the URL as a sub-path, like /en for English and /es for Spanish.
🎯 Goal: Create a Next.js app that uses sub-path routing to show content in English or Spanish based on the URL prefix /en or /es.
📋 What You'll Learn
Create a Next.js page component that shows a greeting message.
Add a configuration variable to define supported locales.
Use Next.js routing to detect the locale from the URL sub-path.
Render the greeting message in the correct language based on the locale.
💡 Why This Matters
🌍 Real World
Many websites support multiple languages and show the language in the URL to help users and search engines understand the content language.
💼 Career
Knowing how to implement locale-based routing is important for building internationalized web apps that reach a global audience.
Progress0 / 4 steps