登录路由未在注销时呈现

时间:2018-11-26 09:33:47

标签: javascript reactjs redux react-redux

我是react js的新手。现在,在这里,我有一条私人路线。

prepHref(image){
    $.fileDownload('https://1.bp.blogspot.com/xDskNs1CNhU/W_uw44XJ70I/AAAAAAAAGTg/3trA_Gh3GsojvuhQ1eljASYla7Y5SulGQCLcBGAs/s200/Fadex.jpg')
       .done(function () { alert('File download a success!'); })
       .fail(function () { alert('File download failed!'); });
}

在这里,第一个是我成功登录后。 因此,登录成功后,我写的像是

 const PrivateRoute = ({ component: Component, isFetching, hasUserLogIn, path, ...rest }) => {
  hasUserLogIn = localStorage.getItem("access_token");
  if (hasUserLogIn !== undefined && hasUserLogIn !== null) {
    hasUserLogIn = true;
  } else {
    hasUserLogIn = false;
  }
  console.log("hasUserLogIn",hasUserLogIn);
  return hasUserLogIn ?
    (
      <Route
        {...rest}
        path={path}
        component={Component}
      />
    )
    :
    (
      <Redirect
        to={{
          pathname: "/login",
          state: { from: path }
        }}
      />
    )
};


  <div>
        <Router history={history}>
          <div>
            {this.props.isFetching && <Loading />}
            <Switch>
              <PrivateRoute exact path="/:job?" component={LandingScreen} />
              <PrivateRoute exact path="/quiz-setup/:job" component={QuizSetupMain} />
              <PrivateRoute exact path="/quiz-questions" component={FetchedQuestionComponent} />
              <Route exact path="/login" component={LoginComponent} />
              <Route exact path="/*" component={NotFound} something="foo" />
            </Switch>
          </div>
        </Router>
      </div>
    )

handleLogout = () => {
    this.props.logoutUser();
  }

现在,我确实有一个下拉列表,更改之处在于,我在类似的路线中添加了history.push('/'); then it redirects to the LandingScreen Component. 参数,

:job

onchange

因此它再次放弃了 history.push({ pathname: "/" + `${jdId}` }); 组件。

现在,单击注销按钮,

我想将使用重定向到LandingScreen的登录页面。

因此,点击注销后,我要做的是

/login

因此,它不会呈现LoginComponent,并且route也不会得到更改, 但是,如果我从路由中删除localStorage.clear(); history.push('/'); ,它将重定向到登录名,则意味着呈现登录组件。

有人可以帮我吗?

0 个答案:

没有答案
相关问题