如何解决为什么 history.push 在历史堆栈中产生 2 个对象,react-router-dom
我正在使用“react-router-dom”库。
import { useHistory } from 'react-router-dom';
const App = () => {
window.lib_history = useHistory();
return /*doesnt matter*/;
}
我从控制台推送了一些页面,但在浏览器历史记录和库历史记录 2 中出现了对象。
/*in console*/
console.log(window.history.length,lib_history.length); // return 11 10 <--it is okay
lib_history.push('/page2'); // redirect successfully
console.log(window.history.length,lib_history.length); // return 13 12 < -- why not 12 11??
作为一个主要问题 - 用户必须点击浏览器后退按钮 2 次才能获得上一页。 我应该在哪里寻找问题?
解决方法
我的项目中有一个 Iframe,它破坏了整个浏览器选项卡的历史堆栈。 感谢您提供有关设置历史记录的提示,这也很有帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。