react 页面跳转
1.使用useHistory跳转
import { useHistory } from 'react-router-dom'
const history = useHistory()
const goPage = () => {
history.push('/路由')
}
2.返回上一页
// 如果使用hashHistory,哈希路由,路由上会加上#
import creatHistory from 'history/createHashHistory'
// 如果使用createBrowserHistory,浏览器路由
import creatHistory from 'history/createBrowserHistory'
const history = creatHistory()
history.goBack()
const goBackPage = () => {
history.goBack()
}
或者直接使用 window.history.back()
const goBackPage = () => {
window.history.back()
}
本文介绍了如何在React中使用useHistory进行页面跳转,并详细讲解了在hashHistory和createBrowserHistory环境下返回上一页的方法,包括使用goBack()函数和window.history.back()。
&spm=1001.2101.3001.5002&articleId=120719428&d=1&t=3&u=d48a8c1e54d44df3a829ac49a35a6b11)
3650

被折叠的 条评论
为什么被折叠?



