Sometimes I use withRouter to wrap my component and use history, location from props, sometimes I use useHistory(),
history
location
props
useHistory()