My route is dynamic:
test/[id].js
When a user clicks on a link to /test/1
, Next.js successfully renders the correct page.
The issue arises when I try to mask the /test/1
URL with something else.
<Link href="/test/1" as="/any/thing/here">
Based on my understanding, the above code should:
- redirect the user to test/1 and render test/[id].js,
- conceal the domain.com/test/1 URL behind domain.com/any/thing/here.
However, it does not point to test/[id].js at all, instead returning a 404 error.
Here is the sandbox link with the broken code:
https://codesandbox.io/s/nervous-silence-z62s1?file=/pages/index.js
What am I doing wrong here? I have very complex URLs with many slashes that I need to use with Next.js dynamic routing, and using "as" seems to be the only solution. I'm fairly certain I used this method successfully a few years ago! It appears to have worked for this individual as well: Linking to dynamic routes in Next.js
If Next.js has made any changes, how can I easily recreate this functionality?