sst.dev icon indicating copy to clipboard operation
sst.dev copied to clipboard

Comments: Redirect on Login and Logout

Open jayair opened this issue 9 years ago • 6 comments

Link to chapter - http://serverless-stack.com/chapters/redirect-on-login-and-logout.html

jayair avatar Apr 10 '17 01:04 jayair

Hi, @jayair.

I was wondering if I have misunderstanding in history props.

I thought when we use , it's the component that handles down history props to react componetns and had nothing to do with withRouter. I thought using withRouter is to recognize changes in the url and rerenders react component.

Am I getting this wrong?

deepseafishing avatar Jul 30 '17 23:07 deepseafishing

@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?

jayair avatar Jul 31 '17 01:07 jayair

"""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 avatar Jul 31 '17 01:07 deepseafishing

@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 avatar Jul 31 '17 01:07 jayair

@jayair Great! your answer made everything so clear. Thanks You, Jayair! I'm getting so much help from this tutorial.

deepseafishing avatar Jul 31 '17 01:07 deepseafishing

This issue was moved to https://discourse.serverless-stack.com/t/comments-redirect-on-login-and-logout/154

jayair avatar May 09 '18 20:05 jayair