[英]Prevent history navigation from causing reload in React
In React, this.props.history.goback()
and this.props.history.go(-1)
are used to go back to the previous page in the browser. 在React中,
this.props.history.goback()
和this.props.history.go(-1)
用于返回浏览器中的上一页。 However, these cause the page to hard-reset (ie, reload) when redirecting to the previous page. 但是,这些导致页面在重定向到上一页时被硬重置(即重新加载)。
Is there any way to prevent the page from refreshing in an SPA using React? 有什么方法可以阻止页面使用React在SPA中刷新吗?
If you use BrowserRouter
, there should be no reloading within your origin. 如果您使用
BrowserRouter
,则您的原点内不应进行任何重载。
import { BrowserRouter } from 'react-router-dom'
<BrowserRouter>
<App/>
</BrowserRouter>
You could try using window.history.back()
. 您可以尝试使用
window.history.back()
。
HTML 的HTML
<button onclick="goBack()">Go Back</button>
JavaScript 的JavaScript
function goBack() {
window.history.back();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.