Private and Protected Routes in React (using React Router v6)

  Рет қаралды 13,972

Studytonight with Abhishek

Studytonight with Abhishek

Күн бұрын

In this video, I have covered how you can create Private and Protected Components in your reactJS application that can only be accessed after Login or some sort of Authentication.
When you create any Product, you have to setup authentication and authorization and some parts of the application are only accessible after authentication if you have different user roles in your app then you should even check for permissions to access ReactJS components.
In this video you will learn all this, along with best practices for React routing where I have used createBrowserRouter to setup routing, and everything is DECOUPLED, and DISTRIBUTED, hence a SUPER SCALABLE design.
Watch the video till the end, and do leave your precious comments.
ReactJS Complete Tutorial: • ReactJS Course for Beg...
Github Repo: github.com/thi...
I hope you enjoy this video and learn something new.
If you do not know JavaScript, then you must learn JavaScript before starting ReactJS, and I have an amazing FREE course for JavaScript to help you learn JS - www.studytonig...
Follow me on Instagram:
Studytonight with Abhishek - / study.tonight
Abhitonight (Hindi Reels) - / abhitonight
LinkedIn: / ahlawatabhishek
Keywords:
learn reactjs
reactjs tutorial
reactjs complete tutorial
reactjs tutorial 2023
reactjs complete tutorial 2023
reactjs beginner tutorial
react tutorial beginner
react tutorial 2023
learn react 2023
react interview question
reactjs interview question
reactjs projects
protected components reactjs
private components reacts

Пікірлер: 20
@kmdoll
@kmdoll 5 ай бұрын
Finally!! the solution at 16:59 was so helpful. Thank you!
@vaibhavkadu140
@vaibhavkadu140 4 ай бұрын
I have tried this it works well with hardcoded user, I'm having an issue when im fetching user roles using axios and passing it to context, but when user tries url manually and hit enter context becomes null and no aceess or login page gets displayed. I can fetch logged in user roles in app but how to pass to context as it is in Root? App has route provider Or in have to call api from protected as well, but i dont want to it because i have landing page same as home in this example, on landing im controlling menus based logged in user roles, I thought of using context user to check if user has required roles to access menu if yes making it visible
@juansalinas788
@juansalinas788 6 ай бұрын
I'm using typescript with React and it's not working for me when creating a Router.ts file and separating the routes.
@Studytonight
@Studytonight 5 ай бұрын
Were you able to fix this?
@juansalinas788
@juansalinas788 5 ай бұрын
@@Studytonight I left it like that, friend
@TheFinanceFix-bb6hx
@TheFinanceFix-bb6hx 4 ай бұрын
thanks sir
@omarsam1
@omarsam1 7 ай бұрын
Thanks, Bro
@Studytonight
@Studytonight 6 ай бұрын
My pleasure :)
@kiranaryal1877
@kiranaryal1877 7 ай бұрын
Thankyou brother
@Studytonight
@Studytonight 7 ай бұрын
Thanks for the comment brother 🥰
@sanujitmajhi4232
@sanujitmajhi4232 7 ай бұрын
import './App.css'; import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; // Import Routes and Route import { Home } from './pages/Home'; import { Login } from './pages/Login'; import { Header } from './components/Header'; import { Private } from './utils/Private'; function App() { return ( {/* Wrap Route in Routes */} {/* Wrap Route in Routes */} ); } export default App; bro why it is not woking
@gopinathkrm58
@gopinathkrm58 5 ай бұрын
nice
@Studytonight
@Studytonight 5 ай бұрын
Thanks
@kashmirtechtv2948
@kashmirtechtv2948 6 ай бұрын
Why this root, router file and userouter context
@Studytonight
@Studytonight 5 ай бұрын
Root for Layout, Router file to define the Routing mechanism, and context to supply states to each child component.
@justarshad404
@justarshad404 7 ай бұрын
informative video
@Studytonight
@Studytonight 6 ай бұрын
Thanks :) Watch other videos in this Playlist too
@theoronno7709
@theoronno7709 3 күн бұрын
painful video, too long and half unimportant thing, and wasting time
@Studytonight
@Studytonight 3 күн бұрын
@@theoronno7709 hmmm 🧐 I will keep that in mind while creating the future videos. Thanks for the comment.
When to use Render Props Pattern in ReactJS?
32:31
Studytonight with Abhishek
Рет қаралды 1,5 М.
Worst flight ever
00:55
Adam W
Рет қаралды 25 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 18 МЛН
Electric Flying Bird with Hanging Wire Automatic for Ceiling Parrot
00:15
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 69 МЛН
Learn React Router v6 In 45 Minutes
46:20
Web Dev Simplified
Рет қаралды 559 М.
React Router Tutorial - 15 - Authentication and Protected Routes
19:46
Custom Protected Route Component in React
10:58
Cosden Solutions
Рет қаралды 44 М.
React Routing - Better & scalable Architecture 💜
18:24
Studytonight with Abhishek
Рет қаралды 6 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
React protected routes in 4 minutes
4:03
Appwrite
Рет қаралды 15 М.
🚀 useContext, Context Provider, etc. - All about Context API in React
36:31
Studytonight with Abhishek
Рет қаралды 3,5 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 661 М.
Worst flight ever
00:55
Adam W
Рет қаралды 25 МЛН