import React from "react";
import { useParams, useLocation, useNavigate } from "react-router-dom";
//高阶组件
const withRouter = (Com) => {
function WithFun(props) {
const params = useParams(); // 接受参数的作用
const location = useLocation(); // 跳转
const navigate = useNavigate(); // 替换以前版本的history
return <Com {...props} router={{ params, location, navigate }} />;
}
return WithFun;
};
export default withRouter;
react 路由6.2版本封装一个withRouter的高阶函数
最新推荐文章于 2024-05-14 09:49:57 发布