import {Link, useNavigate} from 'react-router-dom';
function Home() {
you can pass your state like so: navigate('/show',{state});
const toShowInfoPage=()=>{
navigate('/show');
}
return(
<>
/*you can use button as well or anything
of your choice, but remember
you have to pass the onClick event.
*/
<a
onClick={()=>{toShowInfoPage()}}
style=\{\{textDecoration:'none',
paddingRight:'20px',
color:'#187bcd',
cursor:'pointer'}}>
</>
)
}
要使用类组件访问 useNavigate () ,您必须要么转换为函数组件,要么滚动自定义的 withRouter Higher Order Component 来注入“路由道具”,就像 react-router-dom v5.x 中的 withRouter HOC 所做的那样。