I am new to Next.js, and setting up my routing mechanism according to documentation by arranging file structuring as :
pages/questions/[id].js
I would like to know if there is cool/easier way to get matched id on my page; like in React Router (match.params.id). I don't want to parse window.location.pathname as my first option.
OK, It was just in beginning of the documentation, my bad i did't read :
import { useRouter } from 'next/router'
const Post = () => {
const router = useRouter()
const { pid } = router.query
return <p>Post: {pid}</p>
}
export default Post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With