Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
El middleware Next-JS ( NextRequest.nextUrl.locale ) devuelve una cadena vacía en la implementación

Tengo un error en el middleware next-js

en la función de middleware es devolver un cochecito NextRequest en los documentos nextjs dicen:

 The NextRequest object is an extension of the native Request interface, with the 
following added methods and properties:

- cookies - A Map with cookies from the Request. See Using cookies in Middleware
- nextUrl: Includes an extended, parsed, URL object that gives you access to Next.js 
- specific properties such as pathname, basePath, trailingSlash and i18n. Includes the 
- following properties:
- basePath (string)
- buildId (string || undefined)
- defaultLocale (string || undefined)
- domainLocale
 - defaultLocale: (string)
 - domain: (string)
 - http: (boolean || undefined)
 - locales: (string[] || undefined)
- locale (string || undefined)

eso significa que puedo acceder a la configuración regional actual desde NextRequest.nextUrl.locale. bueno, esto funciona en localhost y ya tengo una configuración regional.

pero después de implementar el proyecto en netlify e imprimir NextRequest.nextUrl.locale en la consola, por lo tanto

 console.log({locale: NextRequest.nextUrl.locale});

me es devuelto

 { locale: "" }

lo que significa NextRequest.nextUrl.locale = "" y cadena vacía

porque este bicho??

ese es mi codigo

 const middleware = async (req) => {
 if (
 req.nextUrl.pathname.startsWith("/_next") ||
 req.nextUrl.pathname.includes("/api/") ||
 PUBLIC_FILE.test(req.nextUrl.pathname)
 ) {
 return;
 }
 
 
 console.log({locale: req.nextUrl.locale});

 return;
};

export { middleware };

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¿Recordó agregar enrutamiento internacionalizado a su next.config.js?

https://nextjs.org/docs/advanced-features/i18n-routing

Mi experiencia es que la configuración regional solo se completa cuando se usa i18n.

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!