history.push跳转传值

63 阅读1分钟
// 组件A
import { history } from 'umi'
<div onClick={() => history.push({pathname:'url', state: {type: 'all'}})}></div>

在组件A中,通过state就可以传想要传的值,另一个组件B接收的话,

// 组件B
import { useLocation } from "umi";
const location = useLocation ();
console.log(location?.state?.type, 'location?.state?.type')

就可以拿到type的值。

赞我.png