繁体   English   中英

在 ReactJS 中使用 history api

[英]Using history api with ReactJS

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

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

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

然后在您的代码中,您将执行以下操作:

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

使用历史。 然后是您要使用的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM