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

1.1K
Views
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 answers
Answer question

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 Report

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 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!