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

1.2K
Visualizações
Get path parameter on Next.js API

I have the following file

pages/api/[slug]/[uid].ts

And I want to get the slug and the uid on the body of my handler, how can I do it?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can access it with req.query Just console.log it and see docs for more https://nextjs.org/docs/api-routes/dynamic-api-routes

about 4 years ago · Juan Pablo Isaza Relatório

0

You can make use of the useRouter() custom hook provided by the next for accessing query params in NextJs. It will return an object which will contain details of the url loaded, including the query params. The params will be stored within query key in the returned object. The query itself has an object as value, where key is the param name (here slug and uid) and its dynamic values as the values.

Then we can make use of the object destructuring for drilling into the required params.

  const router = useRouter();
  const { slug, uid } = router.query;

For accessing single param, we can do as follows,

  const router = useRouter();
  const slugValue = router.query.slug;
  const uidValue = router.query.uid;
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