I am trying to do the following:
<tbody>
{projects.map(function(project, i) { return (
<tr key={i}>
<td>
{project.id}
</td>
<td>
<a href='#/systemlist?projId={project.id}'>{project.name}</a>
</td>
</tr>
);} )}
</tbody>
It should point to another component, using router. It all works, except the {project.id} not being rendered as a value. How to do that? Everything else outside of href works.
This href attribute contains the URL or path to the destination page. It may be a relative URL or an absolute URL. In React, relative URLs should always be handled by the link tag provided by the React Router, and pure anchor tags should only be used for absolute paths.
To add the link in the menu, use the <NavLink /> component by react-router-dom . The NavLink component provides a declarative way to navigate around the application. It is similar to the Link component, except it can apply an active style to the link if it is active.
To set an onClick listener on a link in React:Set the onClick prop on the link. The function you pass to the prop will get called every time the link is clicked.
There are couple ways how you can solve this issue
String concatenation
<a href={ '#/systemlist?projId=' + project.id }>{project.name}</a>
ES2015 string templates
<a href={ `#/systemlist?projId=${project.id}` }>{project.name}</a>
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With