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

326
Views
How to convert [id] to [slug] url in nextjs

I am working on nextjs and i have "blog" list and after click on blog,page redirect to "blog detail page" And current url is like

"http://localhost:3001/29"

Which is working fine,But i want my url should be like

http://localhost:3001/slug/posttitle

My current code for "Link" is which is working fine

<Link href={{pathname: "/[id]",query: { id: post.id },}}>

But for change "id" to "slug" in url,i tried with following code

<Link href={{pathname: "/[slug]",query: { title: post.title },}}>

But my url convert to "http://localhost:3001/[slug]?id=myslug"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since your root page "/" is already your blog section which contains the list of all your blog posts previews, you could create a folder called article inside the pages folder for example, and then inside that folder create your dynamic post page based on the post's slug: [slug].js. So the route would be: example.com/article/your-post-slug.

Inside your [slug].js page, you need to use getStaticPaths and getStaticProps to pre-render all the paths for each individual post and also, the content for each one.

Of course, in your main page you also have to use getStaticProps to fetch all your posts.

In your main page, wrap each post preview with a Link that points to: /article/${slug}. Hope that helps.

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!