Skip to content

feat: Encode non-ASCII characters in pathnames returned from navigation APIs#1922

Merged
amannn merged 3 commits intocanaryfrom
feat/encoded-pathnames-navigation
Jun 11, 2025
Merged

feat: Encode non-ASCII characters in pathnames returned from navigation APIs#1922
amannn merged 3 commits intocanaryfrom
feat/encoded-pathnames-navigation

Conversation

@amannn
Copy link
Copy Markdown
Owner

@amannn amannn commented Jun 11, 2025

With #959, the middleware already handled decoding of non-ASCII characters.

This allows you to define localized pathnames like so:

import {defineRouting} from 'next-intl/routing';
 
export const routing = defineRouting({
  locales: ['en', 'ja'],
  defaultLocale: 'en',
  pathnames: {
    '/about': {
      'de': '/über-uns'
  }
}

Since Next.js automatically encodes incoming pathnames, this supports incoming requests both for decoded pathnames (e.g. /de/über-uns), as well as encoded ones (e.g. /de/%C3%BCber-uns).

One piece has been missing though: Pathnames returned from navigation APIs should be turned into an encoded form.

Now, next-intl handles this as well:

import {Link, getPathname} from '@/i18n/navigation';

// href="/de/%C3%BCber-uns"
<Link href="/about" locale="de" />

// pathname = "/de/%C3%BCber-uns"
const pathname = getPathname({href: '/about', locale: 'de'});

This change brings the navigation APIs in line with Google's recommendation to encode non-ASCII pathnames.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 11:55am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 11:55am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 11:55am

@amannn amannn changed the base branch from main to canary June 11, 2025 12:12
@amannn amannn merged commit 282196c into canary Jun 11, 2025
13 checks passed
@amannn amannn deleted the feat/encoded-pathnames-navigation branch December 29, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant