How can I effectively handle nested dynamic routes and utilize the Next.js Link component?
Let's say I have 2 different file paths:
/pages/projects/index.js
<Link href={`/projects/${project.id}`} key={index}>
<a>Project Name</a>
</Link>
Clicking on this will lead me to localhost:3000/projects/some-id/
and
/pages/projects/[pid]/index.js
I am struggling to understand how to add the path prefix of localhost:3000/projects/some-id/
<Link href={`/${router.pathname}/apple`}>
<a>Business name</a>
</Link>
When using router.pathname
, I get /projects/[pid]/apple
, without the domain, and if I use router.asPath
, I get the correct path but still without the domain. I'm not sure if adding the domain name directly into Link's href
is the right approach.