在 React Class 组件中更改 URL onClick 或 onSubmit 的最佳方法是什么?

What is the best way to change the URL onClick or onSubmit in a React Class Component?

我知道 React 中功能组件的 useHistory 挂钩,但在我的应用程序中我有一个 class 组件,我希望它能够更改 URL.

基于 class 的组件是否有等效的 useHistory?如果不是,可接受的方法是什么?

可能您需要这样的东西:

import { withRouter } from 'react-router-dom'    

export const Component = withRouter(({ history, location }) =>{

})

class Comp extends Component {
    render(){
        const { location, history } = this.props
    }
}
export default withRouter(Comp)

这里回答了一个类似的问题: