Created
May 26, 2017 22:36
-
-
Save xpollen8/cf031fabca5351e11fc4bfd5a00170fc to your computer and use it in GitHub Desktop.
nextjs/link - how to get 'item.id' to evaluate?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Link from 'next/link'; | |
export default () => ( | |
<div> | |
Items | |
<ul> | |
{ | |
[ | |
{ name: 'item one', id: 1 }, | |
{ name: 'item two', id: 2 }, | |
].map( item => | |
<li key={item.id}><Link href='/item?id={item.id}' as='/item/{item.id}'><a>{item.name}</a></Link></li> | |
) | |
} | |
</ul> | |
</div> | |
) |
<li key={item.id}>
<Link href={`/item?id=${item.id}`} as={`/item/${item.id}`}>
<a>{item.name}</a>
</Link>
</li>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When run via "next", those items outside of quotes are evaluated - {item.name} renders properly.
Those within quotes render literally as {item.id}.
What's the magic trick to force evaluation of object items w/in quotes?