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

fix: Handle edge case for localePrefix: 'as-needed', domains & pathnames #1594

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

amannn
Copy link
Owner

@amannn amannn commented Dec 5, 2024

Related to #1107 (comment)

Couldn't find the bug yet, only added tests so far.

Copy link

vercel bot commented Dec 5, 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 Dec 5, 2024 10:51am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 10:51am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 10:51am

expect(MockedNextResponse.redirect.mock.calls[0][0].toString()).toBe(
'http://en.example.com/about'
);
});
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markomitranic I've tried to recreate your case here.

See also the config above:

const middlewareWithPathnames = createMiddleware({
defaultLocale: 'en',
locales: ['en', 'fr'],
localePrefix: 'as-needed',
domains: [
{defaultLocale: 'en', domain: 'en.example.com', locales: ['en']},
{
defaultLocale: 'en',
domain: 'ca.example.com',
locales: ['en', 'fr']
},
{defaultLocale: 'fr', domain: 'fr.example.com', locales: ['fr']}
],
pathnames: {
'/': '/',
'/about': {
en: '/about',
fr: '/a-propos'
},
'/users': {
en: '/users',
fr: '/utilisateurs'
},
'/users/[userId]': {
en: '/users/[userId]',
fr: '/utilisateurs/[userId]'
},
'/news/[articleSlug]-[articleId]': {
en: '/news/[articleSlug]-[articleId]',
fr: '/nouvelles/[articleSlug]-[articleId]'
},
'/products/[...slug]': {
en: '/products/[...slug]',
fr: '/produits/[...slug]'
},
'/categories/[[...slug]]': {
en: '/categories/[[...slug]]',
fr: '/categories/[[...slug]]'
},
'/internal': '/external',
'/internal/foo/bar': {
en: '/external-en/foo/bar',
fr: '/external-fr/foo/bar'
},
'/internal/[id]': {
en: '/external-en/[id]',
fr: '/external-fr/[id]'
},
'/internal/[...slug]': {
en: '/external-en/[...slug]',
fr: '/external-fr/[...slug]'
}
} satisfies Pathnames<ReadonlyArray<'en' | 'fr'>>
});

This seems to be working for me. A redirect to /about is currently added here for compatibility, e.g. when the user switches the domain without changing pathnames.

Can you help me find a failing test?

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