Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 501
Anuj Shaan Avatar asked Dec 30 '25 13:12

Anuj Shaan


1 Answers

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>
like image 81
Drew Reese Avatar answered Jan 01 '26 08:01

Drew Reese



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!