出现这个问题一般是history这个函数不能使用,那么就在hooks中引入这个函数
import {useHistory} from 'react-router-dom'
//下面这句必须写在组件里面
const history=useHistory()
接下来就可以为所欲为的用history.push()
啦
第二种解决方案
使用withRouter
import {withRouter} from 'react-router-dom'
//props.histoty.push()
export default withRouter(Index)