React router this.props.history.push,推送位置,但不呈现组件



我的app.js 中有这个

render() {
//isAuthticated() is async, so we block the rendering until we have the result.
if (!this.state.authenticationChecked) return null;
return (
<div>
<Switch>
<PrivateRoute name={"dashboard"} authed={this.state.isAuthenticated} path="/dashboard" render={(props) => <Calendario {...props} logout={this.logout} />} />
<LifeExpectancyRoute name={"life_expectancy"} path="/lifeExpectancy" render={(props) => <LifeExpectancy {...props} setYearsRedirect={this.setYearsRedirect} />} />
<Route path="/login" render={(props) => <LoginPage login={this.login} authed={this.state.isAuthenticated} {...props} />} />
</Switch>
</div>
)
}
}
export default compose(
withRouter,
connect(null, mapDispatchToProps)
)(App);

Ant然后我有这个函数,当我点击图标时调用它

logout = () => {
this.setState({
isAuthenticated : false,
authenticationChecked: false
}, () =>{
this.props.history.push("/dashboard")
})
}

但出于某种原因,它会推送历史记录,我可以在导航菜单中看到它,但它不会加载组件,我只有一个空白屏幕。如果我在导航栏中手动输入地址,它可以正常工作

这是我的代码逻辑错误,这完成了

logout = () => {
this.setState({
isAuthenticated : false,
authenticationChecked: true
}, () =>{
this.props.history.push("/login")
})
}

最新更新