Localeprefix: as-needed makes nextjs14 crash when navigating to another page
Unanswered
Nelson's Sharp-tailed Sparrow posted this in #help-forum
Nelson's Sharp-tailed SparrowOP
I managed to pinpoint it to this, I need the main language to not show any /nl/ in the url, but all the other languages do need to show.
The homepage works fine, but subpages like /contact/ crash it, when I remove as-needed its fixed, but I need the as-needed...
The homepage works fine, but subpages like /contact/ crash it, when I remove as-needed its fixed, but I need the as-needed...
2 Replies
Nelson's Sharp-tailed SparrowOP
Heres my code
import createMiddleware from 'next-intl/middleware';
export default createMiddleware({
// A list of all locales that are supported
locales: ['nl', 'en', 'de', 'es'],
localePrefix: 'as-needed',
localeDetection: false,
// Used when no locale matches
defaultLocale: 'nl'
});
export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(nl|es|de|en)/:path*']
};Nelson's Sharp-tailed SparrowOP
I think it works when I change my config to
I'm going to test this further, but does someone understand wtf is going on please?
export const config = {
// Matcher entries are linked with a logical "or", therefore
// if one of them matches, the middleware will be invoked.
matcher: [
// Match all pathnames except for
// - … if they start with `/api`, `/_next` or `/_vercel`
// - … the ones containing a dot (e.g. `favicon.ico`)
'/((?!api|_next|_vercel|.*\\..*).*)',
// However, match all pathnames within `/users`, optionally with a locale prefix
'/([\\w-]+)?/users/(.+)'
]
};I'm going to test this further, but does someone understand wtf is going on please?