mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
We currently have logic spread in multiple places that normalize `nxtP` parameters into their regular names, ie `nxtPfoo` -> `foo`. However we don't apply this same logic to `nxtI`, which conceptually is another parameter but for route interception. As a result, the interception route would 404 when deployed because it'd be missing the interception parameter. This moves the normalization check into a util and updates the spots I could find where we handle `nxtP` to also handle `nxtI`. ### Test Plan Added a new test, and validated via these deploys: **Working**: [Link](https://vtest314-e2e-tests-m889gxi4p-vtest314-ijjk-testing.vercel.app/) **Non-Working**: [Link](https://vtest314-e2e-tests-8sa5t9uau-vtest314-ijjk-testing.vercel.app/) Fixes #62207 Closes NEXT-3204
17 lines
490 B
TypeScript
17 lines
490 B
TypeScript
import { NextResponse, type NextRequest } from 'next/server'
|
|
|
|
export default async function middleware(request: NextRequest) {
|
|
const locale = 'en'
|
|
const { pathname } = request.nextUrl
|
|
const pathnameHasLocale =
|
|
pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
|
|
if (pathnameHasLocale) return
|
|
|
|
request.nextUrl.pathname = `/en${pathname}`
|
|
return NextResponse.rewrite(request.nextUrl)
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
|
|
}
|