小编Rut*_*ati的帖子

在react-router-dom-v6中如何在navigate()中传递道具?

我在我的react-app中使用“react-router-dom-v6”进行导航,并且我有一个场景,我必须从我导航的位置传递对象或ID,如何传递对象或任何id?我尝试使用导航功能,但当我使用“useParams()”时它没有给我任何结果。

下面是我用于导航的代码

  //page from where I navigate>>>

    const navigate = useNavigate();

    const on Press Edit = (item)=>{
  //here item is object containing {name, id, email, number}
        console.log('edit..', item)
        navigate("/editemployee", { id: "25", item :item })
      }
      
      
  //page I navigated

    const params = useParams();
      const location = useLocation();
      
      console.log('params', params, location)
      
  //op>>
    //params: prototype object
    // 
    //location: {hash: ""
    //key: "kixzun7e"
    //pathname: "/editemployee"
    //search: ""
    //state: null}
Run Code Online (Sandbox Code Playgroud)

reactjs react-router react-router-dom

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

react-router ×1

react-router-dom ×1

reactjs ×1