Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Reactjs 删除react路由器中的历史记录条目_Reactjs_Typescript_React Router - Fatal编程技术网

Reactjs 删除react路由器中的历史记录条目

Reactjs 删除react路由器中的历史记录条目,reactjs,typescript,react-router,Reactjs,Typescript,React Router,我有一个显示设置链接的左导航 <Link to="/settings"> Settings </Link> 此数组中的第一个设置为子菜单上的默认选择,并向右渲染。它在子菜单中也显示为活动状态。我还使用此默认值来操作浏览器URL,这样用户就不会看到“/settings” 因此,“../settings”变成了“../settings/users” 此时,“/settings”是最后一个位置,“/settings/users”是当前位置。当您点击后退按钮时,它试图返回

我有一个显示设置链接的左导航

<Link to="/settings">
   Settings
</Link>
此数组中的第一个设置为子菜单上的默认选择,并向右渲染。它在子菜单中也显示为活动状态。我还使用此默认值来操作浏览器URL,这样用户就不会看到
“/settings”

因此,
“../settings”
变成了
“../settings/users”


此时,
“/settings”
是最后一个位置,
“/settings/users”
是当前位置。当您点击后退按钮时,它试图返回到
“/settings”
,但不可避免地会根据代码再次追加
“/users”
。是否可以避免在路由历史记录中添加设置,或在添加后将其删除?或者我可以采取一种不同的、更合适的方法,不涉及对历史进行黑客攻击吗?

您是否尝试过
历史。替换(…)
而不是
历史。推送(…)
?难以置信。我感到羞愧。干杯
routes.push({
   exact: true,
   path: getPath("users"),
   resourceKey: "Users"       
}, {...
if (subMenuRoutes.length > 0) {
   if (getURLPath(window.location.href, 5) === "") {
      history.push(subMenuRoutes[0].path as string);
   }
}