Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for custom prefixes for i18n routing #1086

Merged
merged 49 commits into from
Jun 10, 2024

Conversation

amannn
Copy link
Owner

@amannn amannn commented May 23, 2024

Resolves #653

Information

The localePrefix option for createMiddleware as well as the navigation APIs now not only accepts a string, but an object where custom prefixes can be added per locale:

import {LocalePrefix} from 'next-intl/routing';

export const locales = ['en-US', 'de-AT', 'zh'] as const;

export const localePrefix = {
  mode: 'always',
  prefixes: {
    'en-US': '/us',
    'de-AT': '/eu/at'
    // (/zh will be used as-is)
  }
} satisfies LocalePrefix<typeof locales>;

In addition to this implementation, I've restructured the routing docs to discuss config options that are shared among the middleware and navigation APIs on a single page. We might expand on this in the future (see below).

See the docs.

Important: As mentioned in the docs, you might have to adjust your middleware matcher to handle the custom prefixes.

Changes

  • Add support for custom prefixes for i18n routing
  • Fix initial render when passing a relative href to Link (<Link href="about" />)
  • Deprecate import {Pathnames} from 'next-intl/navigation' in favor of import {Pathnames} from 'next-intl/routing'

Potential future changes

I'm considering adding an API like const routing = defineRouting({locales: ['en', 'de'], ...}) to gather all routing-related config. This could be passed as createMiddleware({routing, ...}) (see #779).

(also resolves #940)

Copy link

vercel bot commented May 23, 2024

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 10, 2024 0:14am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2024 0:14am

@amannn amannn changed the title Add support in middleware feat: Add support for custom prefixes May 23, 2024
@amannn amannn changed the title feat: Add support for custom prefixes feat: Add support for custom prefixes for i18n routing May 23, 2024
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.

Path rewriting does not work for the home page Customization of prefixes / multi-tenancy
1 participant