So I want to pass some parameters on a <Link> and I've done the following:
<Link params={{ id: item.id}} to={'/trip/3'}>Book trip</Link>
It works, but I always get a warning in the console:
Warning: Unknown prop params on tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
Is there a way around this using react-router? Thanks
This is happening because the params prop is being added as a prop to the <a> that the <Link> makes. You can include additional information through the state property of the location
<Link to={{ pathname: '/trip/3', state: { id: item.id } }}>
Book trip
</Link>
Edit Is this supposed to add query parameters to the href? For that, you should use the query property of the location.
// item.id = "test"
<Link to={{ pathname:'/trip/3' query: {id: item.id } }}>
Book trip
</Link>
// <a href="/trip/3?id=test>Book trip</a>
@pshrmn Thank you very much, the first solution worked. I didn't need to add parameters in the href, I just needed to pass some data
Most helpful comment
This is happening because the
paramsprop is being added as a prop to the<a>that the<Link>makes. You can include additional information through thestateproperty of the locationEdit Is this supposed to add query parameters to the
href? For that, you should use thequeryproperty of the location.