You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
547 B

2 years ago
  1. // 1.导入 useNavigate
  2. import { useNavigate } from 'react-router-dom'
  3. function Login() {
  4. // 2.执行 useNavigate 得到一个跳转函数
  5. const navigate = useNavigate()
  6. function goAbout() {
  7. // 3.调用跳转函数传入目标路径,{replace: true} 是在跳转时不加入历史记录,不能跳转回登录页
  8. navigate('/about?id=1001', {replace: true})
  9. }
  10. return (
  11. <div>
  12. Login
  13. <button onClick={goAbout}>跳转到about</button>
  14. </div>
  15. )
  16. }
  17. export default Login