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()
}