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

[Docs]: Change Middleware #1002

Closed
pepijnweijers opened this issue Apr 18, 2024 · 1 comment
Closed

[Docs]: Change Middleware #1002

pepijnweijers opened this issue Apr 18, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation unconfirmed Needs triage.

Comments

@pepijnweijers
Copy link

pepijnweijers commented Apr 18, 2024

Link to page

https://next-intl-docs.vercel.app/docs/getting-started/app-router#middleware

Describe the problem

Right now the docs has the following config for the middleware:

export const config = {
  matcher: ['/', '/(de|en)/:path*']
};

The problem with this configuration is that it assumes every first parameter is the language. For instance, if you have a page /example and are working with localePrefix: 'as-needed', it will incorrectly interpret 'example' as your language. Additionally, if I'm using this configuration, it doesn't support dynamic <Link> components. Therefore, if you're on the language /de and link the user to the page 'example', it will generate /example instead of /de/example.

But I feel like the old middleware works better for Next.js:

export const config = {
    matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']
};

Also a suggestion to make localePrefix: 'as-needed', I believe this is better for SEO ;)

@pepijnweijers pepijnweijers added documentation Improvements or additions to documentation unconfirmed Needs triage. labels Apr 18, 2024
@amannn
Copy link
Owner

amannn commented Apr 19, 2024

We initially had localePrefix: 'as-needed' as the default, but there are some gotchas here: Pathnames without a locale prefix.

Based on feedback from users, we've switched to localePrefix: 'always' as the default, as there's typically less to consider for this to work reliably.

Thanks for the feedback though!

@amannn amannn closed this as completed Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants