Report #104335
[bug\_fix] Using \`next/link\` with a dynamic route without template literals, e.g., \`\` but \`id\` is undefined or not string
Use template literals with backticks: \`\` and ensure \`id\` is defined. Alternatively, use the \`as\` prop in older Next.js versions, but in App Router just use string interpolation.
Journey Context:
I had a list of posts and used \`\`. It worked locally, but in production, clicking the link sometimes went to \`/post/undefined\`. I checked the data and post.id was always a number. The issue was that I had a typo: \`post.id\` vs \`post.\_id\`. After fixing the property name, it still occasionally failed because the component rendered before the data loaded. I added a conditional check: \`\{post && ...\`\}. The real fix was using template literals and ensuring the value is defined. Also, I learned that Next.js Link expects a string, not a concatenation that could produce \`NaN\` or \`undefined\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-02T20:05:07.935785+00:00— report_created — created