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
After upgrading from Next.js 15.0.2 to 15.2.4, I'm getting 404s in deployment (Vercel) when accessing dynamic routes without a locale prefix — e.g. /course/:slug now returns 404. This happens when i first visit the dynamic link using next/link.
However when i refresh the page it works fine.
Additionally /tr/course/:courseId (for example) works fine too, and also everything works locally.
App uses app/[language]/course/[slug]/page.tsx
Rewrites are set up in next.config.ts to prepend default locale
Dynamic route worked fine before 15.2.4
https://<deployed_branch_url>/course/:slug --> returns 404 in first visit but works on page refresh
https://<deployed_branch_url>/tr/course/:slug --> works normally
exportfunctionmiddleware(request: NextRequest){returnrunMiddleware(request,[useAuthMiddleware,useI18nMiddleware]);}asyncfunctionuseI18nMiddleware(request: NextRequest,response: NextResponse){if(!pathToRegexp('/((?!_next|api|_vercel|monitoring|.*\\..*).*)').test(request.nextUrl.pathname,)){returnresponse;}const{ pathname }=request.nextUrl;constpathnameHasLocale=!!getAvailableLocaleCodes().find((locale)=>pathname.includes(`/${locale}/`)||pathname===`/${locale}`,);if(pathnameHasLocale){// If the pathname includes the default language, redirect to the path without the default languageif(pathname.includes(`/${DEFAULT_LOCALE_CODE}/`)||pathname===`/${DEFAULT_LOCALE_CODE}`){letnewPathname='';if(pathname.includes(`/${DEFAULT_LOCALE_CODE}/`))newPathname=pathname.replace(`/${DEFAULT_LOCALE_CODE}/`,'');elseif(pathname===`/${DEFAULT_LOCALE_CODE}`)newPathname='/';request.nextUrl.pathname=newPathname||'/';constresponse=NextResponse.redirect(request.nextUrl);response.cookies.set(LOCALE_COOKIE_KEY,pathname.split('/')[1]);returnresponse;}else{response.cookies.set(LOCALE_COOKIE_KEY,pathname.split('/')[1]);returnresponse;}}// If the pathname does not include any locale, add the user's preferred localeconstlocale=getUserLocaleFromRequest(request);// Only add the locale to the pathname if it's not the default languageif(locale!==DEFAULT_LOCALE_CODE){request.nextUrl.pathname=`/${locale}${pathname}`;constresponseNew=NextResponse.redirect(request.nextUrl,{headers: response.headers,});responseNew.cookies.set(LOCALE_COOKIE_KEY,locale);returnresponseNew;}else{response.cookies.set(LOCALE_COOKIE_KEY,DEFAULT_LOCALE_CODE);returnresponse;}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
After upgrading from Next.js 15.0.2 to 15.2.4, I'm getting 404s in deployment (Vercel) when accessing dynamic routes without a locale prefix — e.g. /course/:slug now returns 404. This happens when i first visit the dynamic link using next/link.
However when i refresh the page it works fine.
Additionally /tr/course/:courseId (for example) works fine too, and also everything works locally.
https://<deployed_branch_url>/course/:slug --> returns 404 in first visit but works on page refresh
https://<deployed_branch_url>/tr/course/:slug --> works normally
Additional information
rewrites in next.config.ts
middleware.ts
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions