Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

622
Visualizações
How do I get query string params in NextJS middleware

I'm using NextJS middleware and can get the nextUrl object from the request, which includes things like pathname, but how do I get query string parameters from within the middleware? I can see it comes back as part of the string returned by href which I could then parse myself but I was wondering if it is returned in an object of it's own?

e.g.

export const middleware = (request) => {
  const { nextUrl: { query } } = request;
  ...
};

where query equals

{
  param1: 'foo',
  param2: 'bar',
  etc.
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

nextUrl object already includes searchParams which is a valid URLSearchParams instance.

E.G. usage

export function middleware(req: NextRequest) {
    if(req.nextUrl.searchParams.get('flag')) {
        return NextResponse.rewrite('/feature);
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

As @j-cue said above but I also discovered you can get search from nextUrl.

e.g.

export const middleware = (request) => {
  const { nextUrl: { search } } = request;
  const urlSearchParams = new URLSearchParams(search);
  const params = Object.fromEntries(urlSearchParams.entries());
};
about 4 years ago · Juan Pablo Isaza Relatório

0

You might want to just extract it from a location:

const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda