Anuj Shaan
Anuj Shaan

Reputation: 93

can't pass props using Link in react router dom

enter image description here


 <Link to={{pathname:"/Watch", movie:movie}} >

using this to pass props over Watch page but can't get any value.

I am new to react so there might be silly mistake or might be insufficient information. please let me know regarding any extra info

Upvotes: 3

Views: 5885

Answers (1)

Drew Reese
Drew Reese

Reputation: 203542

If you are using react-router-dom v5 then route state is a property on the to object of the Link.

RRDv5 Link

<Link to={{ pathname: "/Watch", state: { movie } }}>...</Link>

If using react-router-dom v6 then state is a top-level prop.

RRDv6 Link

<Link to="/Watch" state={{ movie }}>...</Link>

Upvotes: 9

Related Questions