Component that protects its children from unauthenticated access. Supports role-based access control.
// Basic protection<ProtectedRoute> <Dashboard /></ProtectedRoute> Copy
// Basic protection<ProtectedRoute> <Dashboard /></ProtectedRoute>
// With redirect (requires react-router or similar)<ProtectedRoute redirectTo="/login"> <Dashboard /></ProtectedRoute> Copy
// With redirect (requires react-router or similar)<ProtectedRoute redirectTo="/login"> <Dashboard /></ProtectedRoute>
// Admin only<ProtectedRoute roles={['admin']}> <AdminPanel /></ProtectedRoute> Copy
// Admin only<ProtectedRoute roles={['admin']}> <AdminPanel /></ProtectedRoute>
// Custom components<ProtectedRoute loadingComponent={<MySpinner />} unauthenticatedComponent={<LoginPrompt />} unauthorizedComponent={<AccessDenied />} roles={['admin', 'editor']}> <EditPage /></ProtectedRoute> Copy
// Custom components<ProtectedRoute loadingComponent={<MySpinner />} unauthenticatedComponent={<LoginPrompt />} unauthorizedComponent={<AccessDenied />} roles={['admin', 'editor']}> <EditPage /></ProtectedRoute>
Component that protects its children from unauthenticated access. Supports role-based access control.