Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
Can I access dynamic route name in next.js middleware?

I have a route at /:username.

In my _middleware.ts file I would like do do something like this

export function middleware(req: NextRequest) {
  const isDynamicRoute = req.nextUrl.pathname === "/[username]";
  
  if (isDynamicRoute) {
    return undefined
  }

  // handle other routes...
}

The issue is that I can't seem to access this dynamic route name in the middleware. I see /test as the pathname instead of /[username].

When I log the request I see what I'm looking for, but it is inside a [Symbol(internal request)] key (along with a separate symbol key that includes the real pathname). Is it possible to access this value reliably in the middleware file? Or do I need to handle this logic in _app.ts? (see log below)

  [Symbol(internal request)]: {
    credentials: 'same-origin',
    headers: BaseHeaders [Headers] { [Symbol(map)]: [Object] },
    method: 'GET',
    referrer: 'about:client',
    redirect: 'follow',
    url: NextURL {
      href: '/test',
      origin: '',
      protocol: '',
      username: '',
      password: '',
      host: '',
      hostname: '',
      port: '',
      pathname: '/test',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    }
  },
  [Symbol(internal request)]: {
    cookieParser: [Function: cookieParser],
    geo: {},
    ip: undefined,
    page: { name: '/[username]', params: [Object] },
    url: NextURL {
      href: '/test',
      origin: '',
      protocol: '',
      username: '',
      password: '',
      host: '',
      hostname: '',
      port: '',
      pathname: '/test',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    }
  }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda