load a component upon passing an id through link

Try this code it’s work’s

Your need to pass id like this !

in my app.js

{
  Items.map((itm) => (
    <Link to={`your api url/+${itm._id}`} />
      <Alert className="question13">{itm.Name}</Alert>
    </Link>
  ))
}

You need to import useRouter for access the query parameter

in my [_id].js file

import { useRouter } from 'next/router'

    const Post = () => {
      const router = useRouter()
      const { _id } = router.query // here `_id` replace with [filename].js
    
      return <p>Post: {_id}</p>
    }
    
    export default Post

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top