# Redirect on Login and Logout

**URL:** https://discourse.sst.dev/t/redirect-on-login-and-logout/154
**Category:** Chapter Comments
**Created:** [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154 "2018-05-09T20:16:17Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/1 "2018-05-09T20:16:17Z")

</div>

_From @jayair on Mon Apr 10 2017 01:04:21 GMT+0000 (UTC)_  
  
Link to chapter - [http://serverless-stack.com/chapters/redirect-on-login-and-logout.html](http://serverless-stack.com/chapters/redirect-on-login-and-logout.html)  
  
_Copied from original issue: [https://github.com/AnomalyInnovations/serverless-stack-com/issues/42](https://github.com/AnomalyInnovations/serverless-stack-com/issues/42)_

---

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/2 "2018-05-09T20:16:18Z")

</div>

_From @deepseafishing on Sun Jul 30 2017 23:54:29 GMT+0000 (UTC)_  
  
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?

---

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/3 "2018-05-09T20:16:18Z")

</div>

_From @jayair on Mon Jul 31 2017 01:20:57 GMT+0000 (UTC)_  
  
@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?

---

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/4 "2018-05-09T20:16:18Z")

</div>

_From @deepseafishing on Mon Jul 31 2017 01:27:00 GMT+0000 (UTC)_  
  
""“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.

---

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/5 "2018-05-09T20:16:18Z")

</div>

_From @jayair on Mon Jul 31 2017 01:51:30 GMT+0000 (UTC)_  
  
@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.

---

<div class="post-metadata">

### Author: ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)
#### Post date: [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/6 "2018-05-09T20:16:19Z")

</div>

_From @deepseafishing on Mon Jul 31 2017 01:57:05 GMT+0000 (UTC)_  
  
@jayair  
Great! your answer made everything so clear. Thanks You, Jayair! I’m getting so much help from this tutorial.

---

<div class="post-metadata">

### Author: ![hlgr360](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/hlgr360/32/835_2.png) [@hlgr360](https://discourse.sst.dev/u/hlgr360)
#### Post date: [April 15, 2020, 10:19am UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/7 "2020-04-15T10:19:02Z")

</div>

FYI: The setup installs a backlevel version of react-router-dom (5.0.1) which does not contain use-history. I had to update the setting in package.json to “react-router-dom”: “^5.1.2”, which does contain ‘use-history’.

---

<div class="post-metadata">

### Author: ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)
#### Post date: [April 25, 2020, 4:48pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/8 "2020-04-25T16:48:43Z")

</div>

Yeah we updated the guide recently to the latest React Router version.

---

<div class="post-metadata">

### Author: ![PrettySolution](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/prettysolution/32/1101_2.png) [@PrettySolution](https://discourse.sst.dev/u/PrettySolution)
#### Post date: [January 14, 2021, 7:59pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/9 "2021-01-14T19:59:59Z")

</div>

Hi there!  
The tutorial says that  
"initialize `useHistory` hook in the beginning of `src/containers/Login.js`"  
but it is not going to work.  
We should initialize it after `export default function Login() {`  
Please, fix that!

---

<div class="post-metadata">

### Author: ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)
#### Post date: [May 15, 2021, 8:26pm UTC](https://discourse.sst.dev/t/redirect-on-login-and-logout/154/10 "2021-05-15T20:26:16Z")

</div>

Yup, added!

> <https://github.com/AnomalyInnovations/serverless-stack-com/commit/39613c72d4a0a2c2ed8d65df1849c0404a7c5118>
