react props 打印为空

react props 打印为空

  1. 下面是我的 app组件

img

  1. 下面是我的 index.js页面

img


3. 下面是我的 打印以及报错信息

img

不知道 这里props为啥打印为空,初学react不知道该如何解决。

你 constructor 传入的 prop少写了 一个s

constructor(props){
        super(props)
    }


react-router v6 解决props为空

import { useLocation, useNavigate, useParams } from "react-router";
export function withRouter(Child) {
  return (props) => {
    const location = useLocation();
    const navigate = useNavigate();
    const params = useParams();
    return (
      <Child
        {...props}
        navigate={navigate}
        location={location}
        params={params}
      />
    );
  };
}