登录重定向React.js后的空白页面

问题描述 投票:0回答:1

登录后我遇到了一个小问题,它将我路由到/ dashboard,但是我得到了一个空白页。但是,如果我仅使用相同的路线/ dashboard刷新页面,则页面正在正确加载。

我已经在沙箱中创建了我的项目的副本=> https://codesandbox.io/s/event-react-3r96m

[可以请您帮我看看吗?我试图使用令牌登录后保持会话状态,但是对于沙箱,我使用user = [email protected]和password = test插入了一个虚拟IF。

谢谢你!最好的祝福!

reactjs redirect router
1个回答
1
投票

问题是您没有更新Auth组件中app.js中的isLoggedIn变量。

在app.js文件中添加以下功能。

  setLoggedIn = () => {
    this.setState ({isLoggedIn: true});
  }

更改以下内容:

            {!this.state.isLoggedIn && (
              <Route path="/auth" component={AuthPage} exact />
            )}

            {!this.state.isLoggedIn && (
              <Route exact path='/auth' render={(props)=>
                <AuthPage {...props} updateStatus={this.setLoggedIn} />}
              />
            )} 

handleSubmit函数内部的Auth.js文件中,调用作为属性传入的新函数。

this.props.updateStatus();

这里是沙盒。https://codesandbox.io/s/event-react-dzs9x

请注意,由于它给了我一个错误,我更改了localStorage调用。

© www.soinside.com 2019 - 2024. All rights reserved.