React useNavigate 和 useLocation的使用
useNavigate 用来跳转并传值// 跳转传值import { useNavigate } from 'react-router-dom'const navigate = useNavigate();function clickCityHandle(city) {navigate('/home', { state: { name: 'zhou' } })}// 接收跳转传过来的值import
·
useNavigate 用来跳转并传值
// 跳转传值
import { useNavigate } from 'react-router-dom'
const navigate = useNavigate();
function clickCityHandle(city) {
navigate('/home', { state: { name: 'zhou' } })
}
// 接收跳转传过来的值
import { useLocation } from 'react-router-dom'
const location = useLocation()
const { state } = location
console.log(location, state);
更多推荐
已为社区贡献1条内容
所有评论(0)