Protected Routes in ReactJS - React Router Dom

Protected Routes in ReactJS - React Router Dom

PedroTech

3 года назад

66,860 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

oussema bouyahia
oussema bouyahia - 14.04.2023 11:40

you could have make it more practical by using input with specified email/password that grant acces to each route after login

Ответить
nowekonto2
nowekonto2 - 27.01.2023 03:54

I think it's time for a new version of 'protected routes' tutorial. This seems outdated.

Ответить
Michael Horvilleur
Michael Horvilleur - 07.10.2022 18:39

As always, he doesn't assume any knowledge of the viewer. Good work!

Ответить
MKSTUD
MKSTUD - 25.08.2022 16:03

you sir are doing the gods work , thank you so much , cant really thank you enough

Ответить
axiomatic22
axiomatic22 - 10.08.2022 16:45

please do again for functional based components

Ответить
Furkan Kurt
Furkan Kurt - 21.06.2022 10:34

why does this fucking library change their code in every 5 days.

Ответить
Philcob Suzuki
Philcob Suzuki - 03.05.2022 11:28

Thank you so much. This is probably the simplest and easy to understand tutorial about Protected Routes

Ответить
Aristos Xanthus
Aristos Xanthus - 24.03.2022 19:34

Creating a dedicated ProtectedRoute for every component is redundant. Is there a way to pass in all components you want to be protected in one statement?

Ответить
richardsan gohil
richardsan gohil - 24.03.2022 10:43

Thank you for this video

Ответить
Max Aquilino
Max Aquilino - 13.03.2022 20:16

Good tutorial, it'd be great if you could do the same for React Router v6

Ответить
John Paul Pineda
John Paul Pineda - 13.03.2022 15:11

Whenever i search a specific video about react. I always find Pedro's tutorial much more understandable compare to the others. :)

Ответить
Mys
Mys - 13.02.2022 20:46

any idea what to use instead of withRouter thats in this video?

Ответить
Willy Horizont
Willy Horizont - 30.01.2022 21:21

sir can you make video of combining protected route and React.lazy and React.Suspense please

Ответить
Singh Saheb
Singh Saheb - 30.01.2022 11:31

Thsnk you !!

Ответить
Samyog Dhital
Samyog Dhital - 28.01.2022 10:31

Love your way of explanation brother! thanks for helping me alot!

Ответить
Ritrik Rohra
Ritrik Rohra - 25.01.2022 15:08

please make with REACT ROUTER DOM 6(six)

Ответить
MrSuperfra89
MrSuperfra89 - 10.01.2022 22:17

how do you not get ncaught Error: [ProtectedRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment> ??

Ответить
Camilo J.
Camilo J. - 07.01.2022 18:16

Thank you! Just one question: is there any change in this workflow with the newest version of React-Router-dom? Or do we still need to do it like in the video? Thanks!

Ответить
Rizqy Fadhilah
Rizqy Fadhilah - 17.12.2021 05:09

Thankyouu!! this is amazing tutorial!! could you tell us which react and react router dom version is being used in this tutorial ?

Ответить
seethal ramakrishnan
seethal ramakrishnan - 02.12.2021 08:58

Hi , how we can check the availability of access token to check user is authenticated in this scenario?

Ответить
manish
manish - 21.11.2021 23:21

What is wrong if i am going to do like this
{
auth ?
(routes to all my protected routers) :
(routes to all my unprotected routers)
}

Ответить
Akash Shrestha
Akash Shrestha - 25.10.2021 16:08

great

Ответить
Riza Radia Rivaldo
Riza Radia Rivaldo - 25.10.2021 06:31

Great content. Very helpfull Thanks

Ответить
Physcript
Physcript - 10.10.2021 09:12

whenever i forgot how to do protected route i always come here hahaha fourth time <3 thx

Ответить
Jaka Krajnc
Jaka Krajnc - 09.10.2021 17:24

What the f**k is Google doing with hindering our boy Pedro in moneitzing his great content? Wtf?

Ответить
jcavenue
jcavenue - 08.10.2021 15:45

Great! Thank you so much!

Ответить
Devesh Rawool
Devesh Rawool - 15.09.2021 15:06

How do I manage state though? It turns out whenever I route to a different path my previous states are lost, for instance whenever I am redirecting from login page to user page the auth state is lost and set to false and I am again redirected to login page. Do I need to use redux for the same? I am new to React js. If anyone can redirect me to a video I will be grateful.

Ответить
Alex Daltsis
Alex Daltsis - 13.09.2021 20:54

Thank you man, you made it very clear :D

Ответить
celroid532
celroid532 - 12.09.2021 19:51

For some reason it is not working for me. It is entering the ProtectedRoute component and the condition isAuth is true, but it just won't render the Profile component, i've tried component={Profile} and component={<Profile/>}, none worked.

Ответить
Bill Papas
Bill Papas - 25.08.2021 01:01

Great tutorial but unfortunately this is not even the 1/10 of making an authentication system in React :(

Ответить
Modou Mbye
Modou Mbye - 15.08.2021 06:24

Great video professor you safe some souls. Thank you very much but please do a video in the case someone has different navigation menu from different users.

Ответить
Swar Drishti Studio
Swar Drishti Studio - 01.08.2021 00:12

Trust me your channel is literally underrated.... I mean seriously man you just blew up my mind... keep posting such informative videos...god bless you

Ответить
Drew Young Thomas
Drew Young Thomas - 28.07.2021 21:30

Hey PedroTech, I'm curious about how you do the line cleanup. Is there a keyboard shortcut youre using to stack your code like that? thanks for all the good work! You've been helping me out a lot with my PERN personal project.

Ответить
JavascriptForEverything
JavascriptForEverything - 28.07.2021 12:59

Thanks

Ответить
GOUROJU SANJAY KUMAR
GOUROJU SANJAY KUMAR - 26.07.2021 19:39

thank you very much, perfect video i was searching all day

Ответить
tarik chuery
tarik chuery - 23.07.2021 03:17

Garotão, parabéns pelo conteúdo! Fera demais a ideia de criar um ProtectRoute!!

Ответить
Deep Patel
Deep Patel - 21.07.2021 07:20

Hey buddy, Great video. Just wanted to add a small thing..Is there any way when the user redirects to login it pops a flash message such like "you need to login to access this page" something like that

Ответить
Colin Pereira
Colin Pereira - 20.07.2021 07:40

absolute "banger"

Ответить
Bhavya Nayyer
Bhavya Nayyer - 19.07.2021 14:31

if we dont have button like i have login page then who should we do

Ответить
Brandon Thomas
Brandon Thomas - 14.07.2021 05:23

Only problem im having is on page refresh it sends me back to "/"

Ответить
Benjamin Nopper
Benjamin Nopper - 09.07.2021 09:56

You forgot one point: How to pass information to the protected route:
You need to add props like this into it: <Component {...props} />

Ответить
Rahul Meghani
Rahul Meghani - 07.07.2021 20:26

I'll not recommend this video to learn react authorization.

Ответить
Sebastian Fritsch
Sebastian Fritsch - 07.07.2021 14:51

The most elegant way, thank you! 🚀

Ответить
Jothinayagan Iyyappan
Jothinayagan Iyyappan - 03.07.2021 16:55

Great explanation. Thanks man.

Ответить
Aragão
Aragão - 26.06.2021 15:36

OBRIGADAAAAA ME SALVOU! <3

Ответить
AsalentsTech
AsalentsTech - 13.06.2021 08:54

i have my user dashboard protected now and if not logged in routes to login form but now i need to connect this to my login can you do a part 2 on how to connect this isAuth with user login page

Ответить
GRACESON SYDON FERNANDES
GRACESON SYDON FERNANDES - 12.06.2021 08:15

the world needs u

Ответить
Adam Jones
Adam Jones - 10.06.2021 20:40

Hey another great video!
Wondering if you know the reason for an error i am getting... (I have tried to join this video with your 2nd in the login series (one with cookies))
I am getting the following when trying to load the protected page - in my case called Home: Error: Invariant failed: You should not use <Route> outside a <Router>
I believe it to be something around the line here:
import React from "react";
import { withRouter } from 'react-router-dom'
function Home() {
return <div>this is a test</div>;

}
export default withRouter(Home); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< as removing the withRouter lets the page load fine (albeit not protected)

<Router>
<Switch>
<ProtectedRoute path="/Home" component={Home} isAuth={isAuth} />
<Route path="/" exact component={Login}></Route>
<Route path="/Register" exact component={Register}></Route>
<Route path="*" exact component={Login}></Route>
</Switch>
</Router>


Have tried going back through the video 3 times and cannot see what i am doing wrong, if you can point it out that would be amazing! Thanks

Ответить
W.WTheDanger
W.WTheDanger - 31.05.2021 20:09

Thanks, man, for an amazing explanation!

Ответить