How to ignore default locale prefix? #1166
-
Is there a way to ignore the default locale prefix in the site? thanks! middleware.ts
i18n.ts
config.ts
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Yes, you're looking for |
Beta Was this translation helpful? Give feedback.
-
Thanks to @amannn's guide, I've worked it out, the key is import createMiddleware from "next-intl/middleware";
export default createMiddleware({
locales: ["en", "de", "fr", "es", "it", "ja", "nl", "pl", "pt", "ru", "sv"],
// 'as-needed' should pass to createMiddleware
localePrefix: 'as-needed',
defaultLocale: "en",
});
export const config = {
// We should skip the internal routes
matcher: ["/((?!api|static|.*\\..*|_next).*)", '/(zh-CN|en)/:path*']
}; |
Beta Was this translation helpful? Give feedback.
-
Thanks @shiny, Hi, @amannn let me know if my case is possible. Let say, I want both "/" and "/en" working, so it should not automatically redirect to "/en" whenever I visit the "/" page. |
Beta Was this translation helpful? Give feedback.
Thanks to @amannn's guide, I've worked it out, the key is
middleware.ts