[英]can't pass props using Link in react router dom
If you are using react-router-dom
v5 then route state is a property on the to
object of the Link
.如果您使用的是
react-router-dom
v5,则 route state 是Link
的to
object 上的属性。
<Link to={{ pathname: "/Watch", state: { movie } }}>...</Link>
If using react-router-dom
v6 then state
is a top-level prop.如果使用
react-router-dom
v6,则state
是顶级道具。
<Link to="/Watch" state={{ movie }}>...</Link>
If you want to pass any state to the component which gets rendered on the path given, you need to paas it in state property of the "to" object as shown here - https://v5.reactrouter.com/web/api/Link/to-object If you want to pass any state to the component which gets rendered on the path given, you need to paas it in state property of the "to" object as shown here - https://v5.reactrouter.com/web/api/链接/对象
So just change your code as below -所以只需更改您的代码如下 -
<Link to={{pathname:"/Watch", state :{movie:movie}}} >
Also, please check the version of react-router in your package.json.另外,请检查 package.json 中 react-router 的版本。 Based on that check the react-router documentation.
基于此检查 react-router 文档。 Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.