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

Поділитися
Вставка
  • Опубліковано 7 лис 2024

КОМЕНТАРІ • 21

  • @kmdoll
    @kmdoll 6 місяців тому +4

    Finally!! the solution at 16:59 was so helpful. Thank you!

  • @vaibhavkadu140
    @vaibhavkadu140 5 місяців тому +1

    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 7 місяців тому +1

    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  6 місяців тому

      Were you able to fix this?

    • @juansalinas788
      @juansalinas788 6 місяців тому +1

      @@Studytonight I left it like that, friend

  • @praveenr7957
    @praveenr7957 Місяць тому

    Thank You🙏

  • @omarsam1
    @omarsam1 8 місяців тому +1

    Thanks, Bro

  • @kiranaryal1877
    @kiranaryal1877 9 місяців тому +1

    Thankyou brother

    • @Studytonight
      @Studytonight  9 місяців тому

      Thanks for the comment brother 🥰

    • @sanujitmajhi4232
      @sanujitmajhi4232 8 місяців тому

      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

  • @TheFinanceFix-bb6hx
    @TheFinanceFix-bb6hx 6 місяців тому +1

    thanks sir

  • @gopinathkrm58
    @gopinathkrm58 7 місяців тому +1

    nice

  • @justarshad404
    @justarshad404 8 місяців тому +1

    informative video

    • @Studytonight
      @Studytonight  8 місяців тому

      Thanks :) Watch other videos in this Playlist too

  • @kashmirtechtv2948
    @kashmirtechtv2948 8 місяців тому +1

    Why this root, router file and userouter context

    • @Studytonight
      @Studytonight  6 місяців тому

      Root for Layout, Router file to define the Routing mechanism, and context to supply states to each child component.

  • @theoronno7709
    @theoronno7709 Місяць тому +1

    painful video, too long and half unimportant thing, and wasting time

    • @Studytonight
      @Studytonight  Місяць тому

      @@theoronno7709 hmmm 🧐 I will keep that in mind while creating the future videos. Thanks for the comment.