Comments: Redirect on Login and Logout
Link to chapter - http://serverless-stack.com/chapters/redirect-on-login-and-logout.html
Hi, @jayair.
I was wondering if I have misunderstanding in history props.
I thought when we use
Am I getting this wrong?
@deepseafishing I'm not sure if I completely get your question but there are a couple of ways to do redirects with React Router v4. We use two of these in our app; use the history prop or use the <Redirect /> component. We are using the history prop here. Are you wondering if we should not use the history prop here?
"""This Higher-Order Component adds the history prop to our component."""
It was this quote that was confusing me. That HOC (which you meant for withRouter) doesn't add the history prop to our component right? I thought it was the Route Component that gives you history prop to our component. I thought withRouter only informs about the change in url to react component so that it can rerender.
@deepseafishing I see what you are saying. The withRouter HOC also gives you the history props. We need this in cases where our component isn't rendered by a <Route />. An example of this is the App component.
But in this case you are right. It is redundant having the withRouter. The history prop should already be available (here and in all our containers). I'll have to test it and update the chapters.
@jayair Great! your answer made everything so clear. Thanks You, Jayair! I'm getting so much help from this tutorial.
This issue was moved to https://discourse.serverless-stack.com/t/comments-redirect-on-login-and-logout/154