You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when using next-intl and internationalized routes with matcher for handling languages (like /fa or /en), internal routes such as /dashboard or any other routes related to different parts of the application are not processed by the middleware. As a result, next-intl fails to recognize and handle these routes properly, causing users to not get redirected to the correct language.
Internal routes like /dashboard are not included in the matcher.
This causes users to not be properly directed to the correct language path when accessing internal pages, and the multi-language setup doesn’t work as expected.
Proposed Solution:
To fix this issue, we need to adjust the matcher configuration so that it includes both internationalized paths and internal routes like /dashboard. Using Regex Negative Lookahead will help us ignore specific paths (like API routes, static files, and meta files) while ensuring that other internal routes are included for processing.
"/" → Covers the home page (root of the site).
"/(fa|en)/:path*" → Handles all internationalized routes (e.g., /fa/dashboard or /en/dashboard).
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)" → Ensures that internal routes like /dashboard are covered while excluding unnecessary paths such as API routes, static files, and meta files.
Outcome:
With this change, all routes are properly processed by next-intl, and users will be able to use the site in multiple languages without issues.
The text was updated successfully, but these errors were encountered:
Link to page
https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#middleware
Describe the problem
Currently, when using
next-intl
and internationalized routes withmatcher
for handling languages (like/fa
or/en
), internal routes such as/dashboard
or any other routes related to different parts of the application are not processed by the middleware. As a result,next-intl
fails to recognize and handle these routes properly, causing users to not get redirected to the correct language.Current
middleware.ts
Configuration:Problem:
Internal routes like /dashboard are not included in the matcher.
This causes users to not be properly directed to the correct language path when accessing internal pages, and the multi-language setup doesn’t work as expected.
Proposed Solution:
To fix this issue, we need to adjust the matcher configuration so that it includes both internationalized paths and internal routes like /dashboard. Using Regex Negative Lookahead will help us ignore specific paths (like API routes, static files, and meta files) while ensuring that other internal routes are included for processing.
export const config = { matcher: [ "/", "/(fa|en)/:path*", // Internationalized routes "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)" // Exclude specific paths ] };
Explanation of the Solution:
"/" → Covers the home page (root of the site).
"/(fa|en)/:path*" → Handles all internationalized routes (e.g., /fa/dashboard or /en/dashboard).
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)" → Ensures that internal routes like /dashboard are covered while excluding unnecessary paths such as API routes, static files, and meta files.
Outcome:
With this change, all routes are properly processed by next-intl, and users will be able to use the site in multiple languages without issues.
The text was updated successfully, but these errors were encountered: