我在我的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)