Authorized routing issue in browserrouter in react
04:08 28 Dec 2025

The below is my router.tsx

The issue in below code is somewhere in student layout, but I cannot figure out what is wrong. As soon as I try to open localhost:5173/ it is checking student auth and redirecting me to /studentauth. And once I am on /studentauth it keeps on infintely redirecting to same page

import React from "react";
import {
  createBrowserRouter,
  RouterProvider,
  Outlet,
  Navigate,
  useLocation,
} from "react-router-dom";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { AuthProvider, useAuth } from "../shared/contexts/AuthContext";
import Protected from "../shared/components/Protected";
import Sidebar from "../shared/components/Sidebar";
import AppErrorBoundary from "../shared/components/AppErrorBoundary";
import NotFound from "../shared/components/NotFound";

import StudentAuthPage from "../modules/auth/pages/StudentAuthPage";

// Registration
import Registration from "../modules/register/pages/Registration";
import StudentRegistrationWizard from "../modules/register/pages/StudentRegistrationWizard";
import Step1College from "../modules/register/pages/Step1College";
import Step2Academics from "../modules/register/pages/Step2Academics";
import Step3Personal from "../modules/register/pages/Step3Personal";
import Finalize from "../modules/register/pages/Finalize";

// Public
import CyclesPage from "../modules/placements/pages/CyclesPage";
import PublicJobsPage from "../modules/placements/pages/PublicJobsPage";
import CycleJobsPage from "../modules/placements/pages/CycleJobsPage";
import JobDetailPage from "../modules/placements/pages/JobDetailPage";

// Student
import StudentHomePage from "../modules/student/pages/StudentHomePage";
import StudentJobsPage from "../modules/student/pages/StudentJobsPage";
import StudentApplicationsPage from "../modules/student/pages/StudentApplicationsPage";
import StudentProfilePage from "../modules/student/pages/StudentProfilePage";

// Admin
import AdminLoginPage from "../modules/admin/pages/AdminLoginPage";
import AdminHomePage from "../modules/admin/pages/AdminHomePage";
import PlacementCyclesPage from "../modules/admin/pages/PlacementCyclesPage";
import PlacementJobsPage from "../modules/admin/pages/PlacementJobsPage";
import PlacementJobDetailPage from "../modules/admin/pages/PlacementJobDetailPage";
import AdminStudentsPage from "../modules/admin/pages/AdminStudentsPage";
import AdminInviteStudentsPage from "../modules/admin/pages/AdminInviteStudentsPage";
import AdminTemplatesPage from "../modules/admin/pages/AdminTemplatesPage";

const StudentLayout: React.FC = () => {
  const { student, hydrated } = useAuth();
  const loc = useLocation();

  if (!hydrated) return null;

  if (!student) {
    return ;
  }


  return (
    
      
); }; import Header from "../shared/components/Header"; const AdminLayout = () => { const { role, hydrated } = useAuth(); if (!hydrated) return null; if (role !== "ADMIN") return ; return (
); }; const PublicLayout: React.FC = () => (
); import LandingPage from "../modules/placements/pages/LandingPage"; import CycleDetailPage from "../modules/admin/pages/CycleDetailPage"; const router = createBrowserRouter([ { element: , children: [ { path: "/", element: }, { path: "/stuauth", element: }, { path: "/adlogin", element: }, ], }, { path: "/student", element: , children: [ { path: "home", element: }, { path: "jobs", element: }, { path: "applications", element: }, { path: "profile", element: }, { path: "placements", element: }, { path: "placements/:cycleId", element: }, { path: "jobs", element: }, { path: "jobs/:id", element: }, { path: "register", element: , children: [ { index: true, element: }, { path: "step1", element: }, { path: "step2", element: }, { path: "step3", element: }, { path: "finalize", element: }, ], }, ], }, { path: "/admin", element: , children: [ { path: "]home", element: }, { path: "placements", element: }, { path: "placements/:cycleId", element: }, { path: "placements/:cycleId/companies/:jobId", element: , }, // Keep legacy route for backwards compatibility { path: "jobs", element: }, { path: "jobs/:id", element: }, { path: "students", element: }, { path: "invite-students", element: }, { path: "templates", element: }, ], }, // catch-all 404 { element: , children: [{ path: "*", element: }], }, ]); const qc = new QueryClient(); const AppRouter: React.FC = () => ( ); export default AppRouter;
reactjs react-router-dom