【发布时间】:2020-07-16 23:23:55
【问题描述】:
我有一个用例,我使用 useHistory 挂钩在组件之间重定向和传递状态。
/* first component */
const {useHistory} from 'react-router-dom';
const history = useHistory();
history.push({pathname: '/next',course: 'some value'});
/* second component */
const location = useLocation();
const value = location.course; /* return 'some value' */
history.push('/nextroute') /* redirects to the third component */
现在,当我从浏览器按返回按钮时,会出现问题,位置状态未定义。现在我有视图,我必须使用“历史”来重定向并将状态传递给组件。当我按下浏览器上的后退按钮或发生页面刷新时,如何保持该状态。还有什么其他效果方式可以为这个特定的用例传递状态。
【问题讨论】:
标签: javascript reactjs react-router-dom browser-history