Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Michael M
Michael M
30 Points

React.js: When using history.push, url changes but Component will not load

I am currently making an app with React and react router that has a login page that validates whether or not a user is logged in, and if they are, it will use history.push to push a <Watchlist /> component. I call this in the render method of my login component here:

    if (this.props.isLoggedIn) {
      history.push('/watchlist');
    }

This will change the url to localhost:3000/watchlist but the actual page itself will not load unless I click refresh. Any reason for this sort of behavior? I can't find a solution anywhere and a similar implementation has worked on other projects. Link to relevant branch in repo: https://github.com/michaelmaryanoff/movieroulettereact/tree/assistance-2-25