【发布时间】:2021-03-01 21:54:56
【问题描述】:
我尝试将数据保存在我的路线中,当我在不同路线之间导航时这些数据会持续存在。但是数据丢失了。
const history = useHistory();
const handleSubmit = () => {
history.push({pathname: '/', state: {
nsin: props.nsin,
assetClass: props.assetClass,
bondsSubclass: props.bondsSubclass,
expCurrency: props.expCurrency,
expCountry: props.expCountry,
instrCategory: props.instrCategory,
nominal: props.nominal,
openEnd: props.openEnd,
callableByIssuer: props.callableByIssuer,
callableByClient: props.callableByClient
} });
}
return (
<button onClick={handleSubmit}>
Overview
</button>
);
然后我尝试访问如下状态:
value={this.props.location?.state?.nsin}
【问题讨论】:
-
你试过用 useLocation 钩子调用它吗?
标签: javascript reactjs state history