我们可以使用导航到不同的路径
this.props.router.push('/some/path')
有没有办法在导航时发送参数(对象)?
我还能想到其他选择,但不知道是否可以通过object
有可能吗?
当前的答案已经过时。
反应路由器 6:
Use the useNavigate
hook:
const navigate = useNavigate();
navigate('/other-page', { state: { id: 7, color: 'green' } });
然后,您可以通过以下方式访问“/other-page”中的状态数据useLocation
hook:
const {state} = useLocation();
const { id, color } = state; // Read values passed on state
React 路由器 4 或 5:
调用history.push,并传递一个对象作为第二个参数来传递状态:
props.history.push('/other-page', { id: 7, color: 'green' }))
然后,您可以通过以下方式访问“/other-page”中的状态数据:
props.location.state
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)