【问题标题】:How to prevent an infinite loop如何防止无限循环
【发布时间】:2021-02-18 16:30:56
【问题描述】:

问题是我已经确定了路线,但特定路线陷入了无限循环

const rootRoute = {
path: '/',
exact: true,
component: () => <Redirect to="/dashboard" />,
route: PrivateRoute,

};

我有这样的路由,但它一直运行到无限循环中,我如何停止循环,仅在未通过身份验证时重定向

【问题讨论】:

    标签: javascript reactjs loops url redirect


    【解决方案1】:

    只需检查是否经过身份验证,然后使用Redirect

    let isAuthenticated = //check if authenticated here
    const rootRoute = {
     path: '/',
     exact: true,
     component: () => isAuthenticated && <Redirect to="/dashboard" />,
     route: PrivateRoute,
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多