Overview
Athena ERP uses react-router-dom v7.13.1 for client-side routing. The routing architecture implements role-based access control, protected routes, and dynamic navigation based on user permissions.Router Setup
Application Root
The router is initialized in the rootApp.tsx component:
src/App.tsx
Route Protection
ProtectedRoute Component
TheProtectedRoute wrapper implements authentication and authorization:
src/components/ProtectedRoute.tsx
- Authentication check: Redirects unauthenticated users to
/login - Authorization check: Validates user roles against
allowedRoles - Location preservation: Saves attempted route in location state for post-login redirect
- Fallback redirect: Unauthorized users redirect to home page
Route Structure
Public Routes
Protected Routes
Dashboard (All Roles)
Admin Panel (Superadmin Only)
Enrollments (Administrative Staff)
Students
Academic Module
Student Conduct
Communications
Settings (Rector & Superadmin)
404 Route
Navigation Components
Layout Navigation
TheLayout component renders navigation based on user roles:
src/components/Layout.tsx
- Filters menu items based on user roles
- Active route highlighting
- Student-specific route redirection (students see only their profile)
- Mobile-responsive drawer navigation
Navigation Hooks
useNavigate
Programmatic navigation:useLocation
Access current location state:useParams
Extract URL parameters:Role-Based Access Control
User Roles
src/store/authStore.ts
Permission Matrix
| Route | Rector | Coordinator | Secretary | Teacher | Student | Acudiente | Superadmin |
|---|---|---|---|---|---|---|---|
/ (Dashboard) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
/admin | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
/matriculas | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
/estudiantes | ✅ | ✅ | ✅ | ❌ | ✅* | ❌ | ✅ |
/academico | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
/convivencia | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
/comunicaciones | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
/configuracion | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
/estudiantes/:id
Password Recovery Flow
src/App.tsx
PASSWORD_RECOVERY event when user clicks reset link in email, automatically redirecting to /reset-password.
Best Practices
Route Organization
- Group related routes: Keep parent/child routes together
- Use nested routes: For layouts and shared components
- Explicit role checking: Always define
allowedRolesfor sensitive routes - Fallback routes: Always include 404 handler
Security
- Never trust client-side checks: Always validate permissions on backend
- Redirect on auth failure: Send users to login, not error pages
- Preserve navigation state: Use location state to redirect after login
- Validate dynamic routes: Check user permissions for
:idroutes
Performance
- Lazy load routes: Use
React.lazy()for code-splitting large pages - Prefetch data: Load data in route loaders for instant navigation
- Optimize redirects: Use
replaceprop to avoid polluting history