How to work of dynamic routes in next.js

Answer

Defining routes by using predefined paths is not always enough for complex applications. In Next.js
you can add brackets to a page ([param]) to create a dynamic route (a.k.a. url slugs, pretty urls, and others).

Consider the following page pages/post/[pid].js:

 

import { useRouter } from 'next/router'

const Post = () => {
const router = useRouter()
const { pid } = router.query

return <p>Post: {pid}</p>
}

export default Post

 

All routes Questions

Ask your interview questions on routes

Write Your comment or Questions if you want the answers on routes from routes Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---