【发布时间】:2021-12-15 16:36:36
【问题描述】:
我在一个名为“ProductCard”的组件中生成了一个带有“navlink”的链接,我想将这些道具传递给一个名为“Product”的组件
ProductCard 组件
import React, {Component} from "react";
import {NavLink} from "react-router-dom";
class ProductCard extends Component{
render() {
return (
<div className="col-xl-4 col-md-6 col-xs-12">
Name : {this.props.product.name}<br/>
Price : {this.props.product.price}<br/>
<NavLink
to={{
pathname:"/product/" + `${this.props.producto.id}`,
aboutProps:{
product_id: `${this.props.product.id}`,
product_name: `${this.props.product.name}`,
product_sku: `${this.props.product.sku}`,
}
}}
exact
> Show product
</NavLink>
</div>
);
}
}
export default ProductCard;
Product.js 组件
import React, {Component} from "react";
class Product extends Component{
constructor(props) {
super(props);
console.log(props.location.aboutProps);
this.state = {
products: []
}
}
render() {
return (
<div className="app container" style={{backgroundColor: "red", padding: "10px"}}>
Product<br/>
</div>
);
}
}
export default Product;
正如我所说,我遇到的问题是能够将父 ProductCard 组件的属性传递给子产品组件
【问题讨论】:
标签: reactjs react-native react-redux react-router