---
title: "Discussion on \"How to prevent React ProtectedRoutes from Redirecting to Login on Page Reload\" | Hashnode"
description: "Discussion on \"How to prevent React ProtectedRoutes from Redirecting to Login on Page Reload\". In standardized applications, it is important to ensure that your users' information is not accessible to anyone but your users.\nOne common way to handle this is through the use of protected routes, which only allow access to specific pages of an app..."
url: "https://hashnode.com/posts/how-to-prevent-react-protectedroutes-from-redirecting-to-login-on-page-reload/63e3a5d659e3880adcdfba14"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to prevent React ProtectedRoutes from Redirecting to Login on Page Reload](https://kodervine.hashnode.dev/how-to-prevent-react-protectedroutes-from-redirecting-to-login-on-page-reload?utm_source=hashnode&utm_medium=feed)

In standardized applications, it is important to ensure that your users' information is not accessible to anyone but your users. One common way to handle this is through the use of protected routes, which only allow access to specific pages of an app...

Feb 8, 2023 · 3 min read · kodervine.hashnode.dev  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#reacthooks](https://hashnode.com/tag/reacthooks)
-   [#programming-blogs](https://hashnode.com/tag/programming-blogs)
-   [#bugs-and-errors](https://hashnode.com/tag/bugs-and-errors)
-   [#frontend-development](https://hashnode.com/tag/frontend-development)

## Written by

[Chinenye Anikwenze](https://hashnode.com/@kodervine)

@kodervine · Remote

  
[View profile](https://hashnode.com/@kodervine)

Software developer && Technical writer

I create stunning user-friendly web apps that engage and simplify the user experience on the client side. I love the intersection of solving customer problems while making their journey seamless. My current focus is building modular AI architectures using n8n, which allows me to deploy private, high-speed automation on self-hosted VPS environments. I am also a technical writer. I share my journey through articles on new technologies, tutorials, and walkthrough into the bugs I encounter. My goal is to explain how I resolved those issues to help other developers build better, faster code

## Responses 1

Markdown supported · ⌘↵ to post

[Egai-Osowor](https://hashnode.com/@egaiosowor)

[Sep 11, 2023](https://hashnode.com/posts/how-to-prevent-react-protectedroutes-from-redirecting-to-login-on-page-reload/63e3a5d659e3880adcdfba14/comment/64fede97703e32bdbc1cffda)

In solution 2, what purpose does the "userUpdated" state serve?

[Chinenye Anikwenze](https://hashnode.com/@kodervine)

[Sep 11, 2023](https://hashnode.com/posts/how-to-prevent-react-protectedroutes-from-redirecting-to-login-on-page-reload/63e3a5d659e3880adcdfba14/comment/64fede97703e32bdbc1cffda#reply-64fee59653e92fc3391129d8)

It is used to store the state of the user and can be reused within the application.

Now, in retrospect, it's over engineering since the developer can access the local storage and store it in state.

Thanks for pointing this out

[Egai-Osowor](https://hashnode.com/@egaiosowor)

[Sep 11, 2023](https://hashnode.com/posts/how-to-prevent-react-protectedroutes-from-redirecting-to-login-on-page-reload/63e3a5d659e3880adcdfba14/comment/64fede97703e32bdbc1cffda#reply-64ff00ebd3da8dcacfaa5d30)

Yeah, that's true. A simpler approach would be to set "isUserSignedIn" to true after successful login and remove it when the user clicks the logout button. The only logic that will be handled on auth change is setting the current user. [Chinenye Anikwenze](https://hashnode.com/@kodervine)
