[英]Using history api with ReactJS
I'm attempting to do history.replaceState()
inside reactjs but I'm getting errors.我正在尝试在 reactjs 中执行
history.replaceState()
但出现错误。 How do I work with the history api inside a reactjs app?我如何在 reactjs 应用程序中使用 history api?
To make use of history (react-router-dom) you need to import it.要使用历史记录 (react-router-dom),您需要导入它。
import { useHistory } from 'react-router-dom';
Then in your code you will do:然后在您的代码中,您将执行以下操作:
export default () => {
const history = useHistory();
return <button onClick={() => history.goBack()}>Go back</button>
}
Use history.使用历史。 then the method you want to use.
然后是您要使用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.