VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Protected Routes in React using React Router

Protected Routes in React using React Router

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
In this video, we will create a protected route using React Router. This route is accessible only when the user is logged in. Link to CodeSandbox: https://codesandbox.io/s/ol6z72kjy9 Tutorial from Nick Karnik. Check out his YouTube channel: https://www.youtube.com/channel/UClCm-WAOgN6XLwCpefSVezg Nick on
Date: 2022-03-14

Comments and reviews: 7


I tried solving a use case using this approach but could not solve it. Have 2-3 open routes, 2-3 protected-routes, and a wild card route at the end of router switch. The protectedRoute being a component renders everything and starts executing whatever logic is inside it. For example, I hit a wild card route /asd and I want to redirect all wild card route to /home. Since protectedRoute component comes before the wild card route in App.js/.tsx the wild card route is never hit and I am redirected to the else condition logic inside my protectedRoute.
reply

Hey, Hello all, I need help, so someone please do help me out as soon as possible. I followed this tutorial to implement protected routing in react, but unfortunately, whenever I refresh the page, I'm going back to the login page. Please somebody help me.
reply

when i was refresh /app profile, thats redirect to homepage. Why? i dont want to redirect from /app to homepage, i want stay in /app after logged in. How can i do it ?
reply

I am wondering, what will happen if you pass random url name, when you are still logged in. In my code, I couldnot show 404 page not found in such condition.
reply

What if the routes I want to protect use the render prop because they render components that have props themselves? I get errors using this method.
reply

I looked up how to hide the Navbar/Header from certain pages ... this didn't help with that but it did clear up other issues I was having....lol
reply

at first 4 secs. of listening to his voice thought it was a text to voice and suddenly after hearing an unexpected words, ... what!!???
reply
Add a review, comment






Other channel videos