React-router: Unknown prop `params` on <a> tag. Remove this prop from the element

Created on 12 Oct 2016  路  2Comments  路  Source: ReactTraining/react-router

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

Most helpful comment

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>

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sarbbottam picture sarbbottam  路  3Comments

Waquo picture Waquo  路  3Comments

ackvf picture ackvf  路  3Comments

yormi picture yormi  路  3Comments

imWildCat picture imWildCat  路  3Comments