React router this.props.history.push , pushing the location but not rendering the component

mouchin777

I have this in my 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 then I have this function which i call when clicking an icon

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

  }

But for some reason, it pushes the history, and i can see it in the navigation menu, but it wont load the component, I just have a blank screen. If i enter the address manually in the navigation bar, it works properly

mouchin777

It was an error with my code logic, this did the trick

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

  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

this.props.history.push not re-rendering react component

React router not rendering the component through history.push()

React history.push() not rendering new component

how to get match, location, history props in react router DOM 5 using component class?

React router `this.props.history.push` - history not defined

Why are the react-router component props not including history?

React - Wrong component rendering after calling history.push

React Router Render props is not rendering component when using params

React Router: Pass this.props.location to navbar component

Reactjs router - this.props.history.push is not rendering URL queries from same path

React router not rendering component

React router not rendering component

React-Router rendering props

React Component not rendering a passed props

react router this.props.location

Automatically redirect with this.props.history.push() on component

open window using react-router v4's this.props.history.push?

Problem when passing props using history.push() in react-router

React Router component rendering twice

React router not rendering path component

React Router not rendering component initially

Menu component with react router not rendering

React Router - Path component is not rendering

React Router not rendering correct component

React Router route not rendering component

React router dom is not rendering a component

Component not rendering using react router

React-router not rendering the component

Constructor props equivalent in React Hooks for history push