Reactjs 超出最大更新深度错误

Reactjs 超出最大更新深度错误,reactjs,cookies,local-storage,Reactjs,Cookies,Local Storage,如果用户手动清除localstorage或cookie令牌,我想重定向到login。如果我根据Cookie'undefined'设置条件,我将得到错误:超过最大更新深度。React限制嵌套更新的数量,以防止无限循环 //components import routes from "./route_config"; import { accessTokenHelper } from "../helper/token" const authed = () =

如果用户手动清除localstorage或cookie令牌,我想重定向到login。如果我根据Cookie'undefined'设置条件,我将得到错误:超过最大更新深度。React限制嵌套更新的数量,以防止无限循环

//components
import routes from "./route_config";
import { accessTokenHelper } from "../helper/token"

const authed = () => localStorage.hasOwnProperty("TOKEN");
const authToken = accessTokenHelper.get();

const authPath = "/login";

const Routes = () => (
  <Router>
    <Suspense fallback={"Loading...."}>
      <Switch>
        {routes.map((route, i) => (
          <Route
            key={route.key || i}
            path={route.path}
            exact={route.exact}
            render={(props) => {
              if (route.authentication && route.path !== authPath) {
                if (authToken) {
                  return <route.component {...props} routes={route.routes} />;
                }
                if (!authToken) return <Redirect to="/login" />;
              }
              if (!route.authentication) {
                if (route.path === authPath) {
                  if (authed()) return <Redirect to="/" />;
                  if (!authed()) return <route.component {...props} />;
                } else if (route.default) {
                  if (authed()) return <Redirect to="/" />;
                  if (!authed()) return <Redirect to="/login" />;
                } else {
                  return <route.component {...props} />;
                }
              }
            }}
          />
        ))}
      </Switch>
    </Suspense>
  </Router>
);

export default Routes;

//组件
从“/route_config”导入路由;
从“./helper/token”导入{accessTokenHelper}
const authed=()=>localStorage.hasOwnProperty(“令牌”);
const authToken=accessTokenHelper.get();
const authPath=“/login”;
常数路由=()=>(
{routes.map((route,i)=>(
{
if(route.authentication&&route.path!==authPath){
如果(authToken){
返回;
}
如果(!authToken)返回;
}
if(!route.authentication){
if(route.path==authPath){
if(authed())返回;
如果(!authed())返回;
}else if(route.default){
if(authed())返回;
如果(!authed())返回;
}否则{
返回;
}
}
}}
/>
))}
);
导出默认路径;