【发布时间】:2021-03-09 02:19:06
【问题描述】:
单击按钮时,我需要将新道具传递给 UnitOverview 并转到链接“OeeUnitOverview”。当我去链接“OeeUnitOverview 到组件将自动加载。 我想打印 OeeUnitOverview 类中的 ID 和名称
<Button
component={Link}
to="OoeUnitOverview"
// render={(props) => <UnitOverview id={5} name={"test"} {...props} />}
// /// <== not working
variant="contained"
style={{ width: "100%" }}
>
Detailscode
</Button>
class UnitOverview extends React.Component<IUnitProps> {
constructor(props: IUnitProps) {
super(props);
}
componentDidMount() {
// console.log("UnitOverview id " + this.state.name);
console.log("id = " + this.props.id);
console.log("name = " + this.props.name);
}
render() {
return <h1>test</h1>;
}
}
interface IUnitProps {
id: number;
name: string;
history?: any;
location?: any;
match?: any;
}
export default UnitOverview;
【问题讨论】:
-
向我们提供Minimal, Complete, and Reproducible 代码示例可能会有所帮助。正在使用什么导航/路由?您想通过导航发送哪些额外的道具?
-
我要发送ID和姓名。
标签: reactjs button hyperlink routes components