Search code examples
javascriptnode.jsreactjsnext.jsnext-router

router.query returning an empty object in next js


my folder structure:

enter image description here

also my code:

const router = useRouter();
const { id } = router.query;

so the problem is the id is returning {} and is not returning the id in the URL. it works fine when I put it in jsx but not when I put it in js


Solution

  • you should name folder is "duc" or "product" or ... and in folder name js should [id].js for dynamic route , not index.js

    Dynamic Routes