我要获取其中的产品列表ProductList,其中需要将选定的产品对象传递给Product。
ProductList
Product
目前,我正在尝试将idas作为路由参数传递,并再次获取product对象。但是我想将整个产品对象从发送ProductList到Product。
id
我的路线是
<Route path={joinPath(["/product", ":id?"])} component={Product} />
ProductList组件链接
<Link to={"/product/" + this.props.product.Id} >{this.props.product.Name} </Link>
如何传递产品对象Product作为道具?
以下内容在Typescript中引发错误,表示LinkType 上不存在以下属性。
Link
<Link to={"/product/" + this.props.product.Id} params={product}>{Name}</Link>
我尝试了以下问题,但似乎没有问题。
<--- this is similar to my issue, but answer doesn't work for react-router v4
的“ to”属性Link可以接受一个对象,因此您可以像这样传递道具:
to
<Link to={ { pathname: "/product/" + this.props.product.Id, myCustomProps: product } }> {Name} </Link>
然后,您应该可以访问它们 this.props.location.myCustomProps
this.props.location.myCustomProps