Internationalised routing in Next.js with the App Router

Put routes under a [lang] segment, prerender each language, serve the default language without a prefix via proxy.ts, and add hreflang. With code.

By Sohail Hussain21 November 20265 min read

Internationalised routing in the Next.js App Router works by putting every route under a dynamic [lang] folder, so /ar/services renders app/[lang]/services/page.tsx with lang set to ar. You prerender each language with generateStaticParams, load translations in server components, add hreflang links through the Metadata API, and use a small proxy.ts if you want the default language to live at the root without a prefix. The built-in i18n config from the Pages Router does not exist in the App Router.

The code is for Next.js 16, current as of October 2026. Translation workflow, right-to-left layout and CMS modelling are covered in building a multilingual Next.js site; this post is about the routing.

Step 1: Which URL structure should you use?

Subfolders, for almost every business: example.com/ for English and example.com/ar/ for Arabic. One domain keeps all the authority in one place, hosting stays simple, and hreflang handles which version Google shows. The Arabic website guide explains why, and subdomain vs subfolder vs ccTLD compares the options.

The second choice is whether the default language gets a prefix too (/en/services) or stays at the root (/services). Prefixing every language is simpler to build. Keeping the default at the root avoids changing every existing URL when you add a language to a live site, which matters for rankings. The code below supports the root option.

The third choice is whether to translate the slugs. /ar/services with an English slug is simpler: one folder serves both languages and the switcher only swaps the prefix. A translated slug matches what Arabic searchers type, but it shows as a long percent-encoded string when the link is pasted into some apps, and it needs a lookup table to map each slug to its translation. Both are valid. English slugs under /ar/ are the cheaper build, which is why many Gulf sites use them; either way, translate everything on the page, including the title and description.

This is the structure we use on bilingual sites in our Arabic and multilingual websites work, built as part of our wider website design and development service.

Step 2: How do you set up the [lang] segment?

Move the root layout and all pages into app/[lang]/. The layout sets the lang and dir attributes and tells Next.js which languages to prerender:

tsx
// app/[lang]/layout.tsx
import { locales } from "./dictionaries";

export function generateStaticParams() {
  return locales.map((lang) => ({ lang }));
}

export default async function RootLayout({ children, params }: LayoutProps<"/[lang]">) {
  const { lang } = await params;
  return (
    <html lang={lang} dir={lang === "ar" ? "rtl" : "ltr"}>
      <body>{children}</body>
    </html>
  );
}

LayoutProps and PageProps are type helpers Next.js generates from your folders. With Cache Components enabled, generateStaticParams is required here: every root parameter needs at least one value or the build fails.

Files such as app/sitemap.ts and app/robots.ts can stay at the top of app/, outside the [lang] folder.

Step 3: How do you load translations?

Keep one JSON dictionary per language and load it only on the server, so translations never add to the JavaScript bundle:

ts
// app/[lang]/dictionaries.ts
import "server-only";

const dictionaries = {
  en: () => import("./dictionaries/en.json").then((m) => m.default),
  ar: () => import("./dictionaries/ar.json").then((m) => m.default),
};

export type Locale = keyof typeof dictionaries;
export const locales = Object.keys(dictionaries) as Locale[];
export const hasLocale = (lang: string): lang is Locale => lang in dictionaries;
export const getDictionary = (lang: Locale) => dictionaries[lang]();

In each page, check the language and load the dictionary:

tsx
// app/[lang]/page.tsx
import { notFound } from "next/navigation";
import { getDictionary, hasLocale } from "./dictionaries";

export default async function Page({ params }: PageProps<"/[lang]">) {
  const { lang } = await params;
  if (!hasLocale(lang)) notFound();
  const t = await getDictionary(lang);
  return <h1>{t.home.title}</h1>;
}

The hasLocale check turns an unknown language such as /fr into a 404 instead of a runtime error. The server-only package (install it with npm) makes the build fail if a client component imports the file.

For deeply nested components, Next.js 16 also offers next/root-params. Because lang is the segment above the root layout, any server component can call await lang() imported from next/root-params instead of passing it down as a prop. The Next.js internationalisation guide shows that version.

Step 4: How do you keep the default language at the root?

Add proxy.ts next to the app folder. (In Next.js 16, proxy.ts replaces the old middleware.ts.) It rewrites unprefixed paths to the default language internally, and redirects anyone who types the prefixed version back to the clean URL, so each page has exactly one address:

ts
// proxy.ts
import { NextResponse, type NextRequest } from "next/server";

const locales = ["en", "ar"];
const defaultLocale = "en";

export function proxy(request: NextRequest) {
  const { pathname } = request.nextUrl;

  // /en/services -> /services, so English has a single URL
  if (pathname === `/${defaultLocale}` || pathname.startsWith(`/${defaultLocale}/`)) {
    const url = request.nextUrl.clone();
    url.pathname = pathname.slice(defaultLocale.length + 1) || "/";
    return NextResponse.redirect(url, 308);
  }

  // /ar/... already names its language
  if (locales.some((l) => pathname === `/${l}` || pathname.startsWith(`/${l}/`))) return;

  // /services is rendered by app/[lang]/services with lang = "en"
  const url = request.nextUrl.clone();
  url.pathname = pathname === "/" ? `/${defaultLocale}` : `/${defaultLocale}${pathname}`;
  return NextResponse.rewrite(url);
}

export const config = {
  matcher: ["/((?!api|_next/static|_next/image|.*\\..*).*)"],
};

The matcher skips API routes, Next.js assets and any path with a file extension, such as sitemap.xml or images in public.

You will see examples that redirect visitors to a language based on their browser's Accept-Language header. Do not do that for every URL. Google's guidance on managing multi-regional and multilingual sites advises against automatic redirects based on perceived language, because they can stop people and crawlers from reaching the other versions. Serve the page that was asked for, and make the language switcher easy to find.

Step 5: How do you add hreflang tags?

Return alternates.languages from each page's metadata, listing every language version including the page itself, plus x-default:

tsx
// app/[lang]/services/page.tsx
import type { Metadata } from "next";

export async function generateMetadata({ params }: PageProps<"/[lang]/services">): Promise<Metadata> {
  const { lang } = await params;
  const path = "/services";
  return {
    alternates: {
      canonical: lang === "en" ? path : `/${lang}${path}`,
      languages: { en: path, ar: `/ar${path}`, "x-default": path },
    },
  };
}

With metadataBase set in the root layout, Next.js turns these into absolute link rel="alternate" hreflang tags. Each language version points to itself as canonical, never to the English page. Add the same alternates.languages to each entry in sitemap.ts; sitemaps and robots.txt in Next.js shows the format. To check a set of URLs by hand, our hreflang generator builds the tags with x-default for you, and hreflang explained covers regional codes such as ar-AE.

The same page in the other language, not the other homepage. A visitor reading /services who switches to Arabic should land on /ar/services. Build the link from the current path in a small client component using usePathname, or pass the translated URL down from the page when slugs differ between languages.

Label each option in its own language, "English" and "العربية", and never use flags for languages. Put a lang attribute on each label, such as lang="ar" on the Arabic one, so screen readers pronounce it correctly.

If you are still on the Pages Router and its built-in i18n config, moving to this setup is one of the larger parts of a migration; App Router vs Pages Router helps decide whether it is worth doing now. For the reasons we build on Next.js in the first place, see why we build company websites with Next.js.

Was this guide useful?

Questions

Frequently asked.

What happened to the i18n option in next.config?

It belongs to the Pages Router. The App Router does not use it, so locale prefixes, detection and default-locale handling are built with a dynamic [lang] segment and, where needed, a proxy.ts file. The extra code is small, and it gives you full control over URLs.

Should I use next-intl or build it myself?

For two or three languages with mostly page content from a CMS, the dictionary approach in the Next.js docs is enough. Use a library such as next-intl when you need plural rules, number and date formatting across many locales, or translated pathnames, because those are tedious to build well.

Should I redirect visitors to their browser language?

Not automatically. Google advises against redirecting based on the visitor's perceived language, because it can stop people and crawlers reaching other versions. Serve the URL that was requested, make the language switcher obvious, and optionally show a small banner suggesting the other language.

Sohail Hussain

Founder, MSH Technologies

Sohail has designed and built websites, web apps and AI products for over 12 years, for clients from Singapore-based industrial groups to early-stage SaaS startups. He writes about what actually worked.

Keep reading

Related guides.

All posts

Your next move

Like what you see? Tell us about it.

A process that takes too long, a website that undersells you, or an idea ready to take shape. Tell us where you are and we will suggest a useful next step.

India · Working with clients worldwide

Sohail, Founder, replies within 1 working day (Mon–Sat, IST). Free and no obligation.