簡體   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