引入:

import { useHistory } from 'react-router-dom';
下面那两个都要引入这个

传输数据:

//注意先引入上面的
const history = useHistory();
function data(){
    history.push('需要数据的路由的url', { state:数据 })
  }

接收数据:

    注意先引入上面的
    const history = useHistory();
    //接收函数
    useEffect(() => {
        //做个判断别没收到报错
        if (history.location.state) {
            //打印看看
            console.log(history.location.state.state)
        }
    }, [])

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐