你能通过 react-router v4 hashHistory 倒退吗?

Can you go backwards through react-router v4 hashHistory?

想知道如何在 react-router v4 中使用 hashRouter 而不是 browserRouter 返回到 React 网络应用程序中的上一个路由?

我发现 这个问题似乎没有用,即使它说不需要浏览器 mixin(而且我认为它在谈论旧的 react-router 版本)但是,我的所有其他解决方案看过依赖browserHistory.

hashHistory 可以吗?

this.props.history.goBack()

摘自

的评论

是函数调用。

好吧,就我而言,我确实喜欢那样:

import withRouter from "react-router-dom/es/withRouter";
import React from "react";

class Component extends React.Component {
  goBack() {
    this.props.history.go(-1);
  }
  ...
}    
const WrappedComponent = withRouter(Component)
export default WrappedComponent;

withRouter 让我们可以访问组件 props 中的历史记录,但我不确定这种方式是否正确