The <Protected /> component allows you to declaratively hide routes based on a boolean condition. When the guard prop is false, wrapped screens are completely filtered out from the navigator - they won’t appear in the navigation state and cannot be navigated to.
This is useful for authentication flows, feature flags, role-based access, or any scenario where routes should be conditionally available.
When session is null/undefined, the dashboard and settings routes don’t exist in the navigation tree. Attempts to navigate to them will be blocked.
<Protected /> works with Stack, Tabs, Drawer, and the base Navigator component:
You can nest <Protected /> components. Routes are only shown when all parent guards are true:
In this example:
public is always availabledashboard requires isLoggedIn to be truepremium-features requires both isLoggedIn AND isPremium to be trueThere are two main approaches to protecting routes:
| Approach | When to Use |
|---|---|
<Protected /> | Routes should not exist when unauthorized |
<Redirect /> | Routes exist but redirect unauthorized users |
Use <Protected /> when routes should be completely hidden - they won’t appear in tab bars, won’t be in the navigation history, and navigation attempts will be blocked.
Use <Redirect /> when you want to intercept navigation and send users to a login page. This is better for deep linking scenarios where you want to redirect to login, then back to the original destination.
You can combine both approaches:
| Prop | Type | Description |
|---|---|---|
guard | boolean | When false, all wrapped screens are filtered out |
children | ReactNode | <Stack.Screen />, <Tabs.Screen />, or other <Protected /> elements |
Edit this page on GitHub.