Javascript reactJS历史推送返回一个错误
嗨,在我的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时,单击链接将替换历史堆栈中的当前条目,而不是添加新条
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)代码>