Reactjs 反应路由器给出的“反应”;重定向到同一路线“;错误

Reactjs 反应路由器给出的“反应”;重定向到同一路线“;错误,reactjs,react-router-v4,react-router-dom,Reactjs,React Router V4,React Router Dom,我有如下路由,如果有人单击主页上的“管理”按钮(此按钮路由到/admin),我想将用户重定向到“管理/用户”页面,但我遇到以下错误: 您试图重定向到当前所在的同一路线: /管理员/用户 我在交换机中添加了位置属性,因为我在布线时使用动画。您可以在以下链接中找到一个示例: 如果我删除位置属性,一切都很好,但使用此属性会出现错误 我搜索了很多网站,尝试了几件事,但都没有成功。我需要位置属性,无法删除它 如果你能帮助我,我将不胜感激 谢谢这不是一个解决方案,但会删除错误 <Switch

我有如下路由,如果有人单击主页上的“管理”按钮(此按钮路由到/admin),我想将用户重定向到“管理/用户”页面,但我遇到以下错误:

您试图重定向到当前所在的同一路线: /管理员/用户


  • 我在交换机中添加了位置属性,因为我在布线时使用动画。您可以在以下链接中找到一个示例:
  • 如果我删除位置属性,一切都很好,但使用此属性会出现错误
  • 我搜索了很多网站,尝试了几件事,但都没有成功。我需要位置属性,无法删除它
如果你能帮助我,我将不胜感激


谢谢

这不是一个解决方案,但会删除错误

<Switch location={this.props.location}>
 <Route path="/" exact component={Home} />
 <Route path="/orders" component={Orders} />
 <Route path="/account" component={Account} />

 <Route path="/admin/users" component={Users} />
 <Route path="/admin/auth" component={Auth} />

 {allowedToRedirect
  ?(
    <Redirect from="/admin" to="/admin/users" />

    <Redirect from="*" to="/" />
   )
  : null}
</Switch>

{允许直接
?(
)
:null}
其中
const allowedToRedirect=location.pathname===window.location.pathname

只有编写以下代码,我才能实现:

<Route exact strict path="/admin" render={({location}) => {
    if (location.pathname === window.location.pathname) {
         return <Redirect to="/admin/users" />;
    }
    return null;
}} />
{
if(location.pathname==window.location.pathname){
返回;
}
返回null;
}} />
但是为什么交换机不阻止一次又一次地运行下面的重定向路由呢?因为当重定向发生时,
/管理员/用户路径有效,但管理员路径也有效。为什么交换机不阻止?有人对此有答案吗?

你能试着删除
?这条可能会覆盖以前的路线不,对不起。我仍然有同样的错误。代码如下:
{/**/}
好吧,因为除了我的消息,我不能评论其他消息-不能回答你对自己问题的新答案(出于某种原因,这与我的完全相同)。这是因为转换的工作方式是这样的。他们用旧道具代表旧观点,用新道具代表新观点。由于您已经重定向到新页面,使用旧道具重定向(位置)会引发此类错误。
<Route exact strict path="/admin" render={({location}) => {
    if (location.pathname === window.location.pathname) {
         return <Redirect to="/admin/users" />;
    }
    return null;
}} />