diff --git a/chenxuan1/src/router/withRouter.jsx b/chenxuan1/src/router/withRouter.jsx new file mode 100644 index 000000000..ed9e52646 --- /dev/null +++ b/chenxuan1/src/router/withRouter.jsx @@ -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 ( + + ); + } + + return ComponentWithRouterProp; + } + export default withRouter; \ No newline at end of file diff --git a/demo/route/read.text b/demo/route/read.text index e12f8a1af..21d914b01 100644 --- a/demo/route/read.text +++ b/demo/route/read.text @@ -22,4 +22,6 @@ 14、push与replace 15、witchRoute 使一般组件拥有路由组件的属性,返回值是一个新组件 16、编程式路由 + this.props.push() + this.props.replace() \ No newline at end of file