简体   繁体   English

为什么history.push在历史堆栈中产生2个对象,react-router-dom

[英]why history.push produce 2 objects in history stack, react-router-dom

I am using 'react-router-dom' library.我正在使用“react-router-dom”库。

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

const App = () => {
    window.lib_history = useHistory();

    return /*doesnt matter*/;
}

From console I push some page, but in browser history and in library history 2 object appeared.从控制台我推送了一些页面,但在浏览器历史记录和库历史记录中出现了 2 object。

/*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??

And as a main problem - user have to click browser back button 2 times to get previous page.作为一个主要问题 - 用户必须单击浏览器后退按钮 2 次才能获得上一页。 Where should I look for problem?我应该在哪里寻找问题?

There was an Iframe in my project which spoiled history stack of whole browser tab.我的项目中有一个 Iframe 破坏了整个浏览器选项卡的历史堆栈。 Thanks for hints about setting up history, it was helpful also.感谢您提供有关设置历史记录的提示,这也很有帮助。

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

相关问题 history.push 到 /login(注销时)在 react-router-dom 中不起作用 - history.push to /login (on logout) is not working in react-router-dom 可以覆盖 React-Router-Dom 的 History.push 方法 - Is possible to override History.push method of React-Router-Dom history.push 使用 react-router-dom - history.push using react-router-dom react-router-dom-链接和history.push之间的区别? - react-router-dom - Difference between link and history.push? 在这种情况下如何使用“history.push”? 反应路由器dom V5 - How Can I Use "history.push" In This Situation? react-router-dom V5 react-router-dom v5 - 链接有效,但 Redirect 和 history.push() 无效 - react-router-dom v5 - Link works, but Redirect and history.push() do not history.push(path)在react-router-dom v4中不起作用,在重定向到404时使用redux - history.push(path) is not working in react-router-dom v4, with redux while redirecting to 404 React-router-dom:History.push 连接路径并且不重新路由应用程序 - React-router-dom: History.push concatenates path and doesn't reroute the app 当第二个 history.push 被触发时,react-router-dom 返回 undefined - react-router-dom return undefined when second history.push is triggered history.push() 使用 react-router-dom 在某些组件中有效,但在其他组件中无效 - history.push() using react-router-dom works in some components but not others
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM