no message
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
useLocation,
|
||||
useNavigate,
|
||||
useParams
|
||||
} from "react-router-dom";
|
||||
// useNavigate 用来跳转用的 函数组件使用 useLocation接收参数用 useParams接收参数
|
||||
function withRouter(Component) {
|
||||
function ComponentWithRouterProp(props) {
|
||||
let location = useLocation();
|
||||
let navigate = useNavigate();
|
||||
let params = useParams();
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
router={{ location, navigate, params }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return ComponentWithRouterProp;
|
||||
}
|
||||
export default withRouter;
|
||||
@@ -22,4 +22,6 @@
|
||||
14、push与replace
|
||||
15、witchRoute 使一般组件拥有路由组件的属性,返回值是一个新组件
|
||||
16、编程式路由
|
||||
this.props.push()
|
||||
this.props.replace()
|
||||
|
||||
Reference in New Issue
Block a user