【问题标题】:Using history api with ReactJS将历史 API 与 ReactJS 一起使用
【发布时间】:2017-07-17 00:17:28
【问题描述】:

我正在尝试在 reactjs 中执行 history.replaceState(),但出现错误。如何在 reactjs 应用程序中使用 history api?

【问题讨论】:

  • 您能否更具体地说明您是如何使用它以及错误是什么?
  • 我想我通过使用react-route-dom找到了解决方案
  • 您能否具体说明您想要做什么。如果您找到了解决方案,请将其作为答案发布。

标签: javascript reactjs html5-history


【解决方案1】:

要使用历史记录 (react-router-dom),您需要导入它。

import { useHistory } from 'react-router-dom';

然后在你的代码中你会这样做:

export default () => {
    const history = useHistory();
 
    return <button onClick={() => history.goBack()}>Go back</button>
}

使用历史记录。然后是你要使用的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-26
    • 2017-02-25
    • 2020-09-21
    • 2016-12-03
    • 2017-08-06
    • 2015-03-13
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多