Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript reactJS历史推送返回一个错误_Javascript_Reactjs - Fatal编程技术网

Javascript reactJS历史推送返回一个错误

Javascript reactJS历史推送返回一个错误,javascript,reactjs,Javascript,Reactjs,嗨,在我的reactJS应用程序中,我使用这个 this.props.history.push("URL"); 当我想重新加载页面时,重定向到另一页或同一页 但我有一个错误: Hash history cannot PUSH the same path; a new entry will not be added to the history stack 我如何解决这个问题 提前感谢您可以使用替换道具。当replace prop为true时,单击链接将替换历史堆栈中的当前条目,而不是添加新条

嗨,在我的reactJS应用程序中,我使用这个

this.props.history.push("URL");
当我想重新加载页面时,重定向到另一页或同一页

但我有一个错误:

Hash history cannot PUSH the same path; a new entry will not be added to the history stack
我如何解决这个问题


提前感谢

您可以使用
替换
道具。当replace prop为true时,单击链接将替换历史堆栈中的当前条目,而不是添加新条目。要获取当前路径名,请使用
props.location

<Link replace={to === location.pathname} to={to}><Button>{to}</Button></Link>
{to}
您可以创建高阶函数并将
包装在其中。所以你可以把它当作

<NavLink to="{to}"></NavLink> 


我想你在找这个

   this.props.history.push({
         pathname: "URL"
      })
你可以用


if(history.location.pathname!==somePath)history.push(somePath)检查此问题是警告还是错误?对我来说似乎是个警告。如果我没有弄错的话,警告只在开发模式下显示,而在生产模式下不显示。只需检查新位置是否与当前位置相同
const{history}=this.props;if(history.pathname!==newPath)history.push(newPath)