Skip to main content
hidden() is a helper function that returns a guard result indicating access should be denied with a 404 response.

Type Signature

Behavior

When a guard returns hidden():
  • Route is inaccessible: The route cannot be accessed via URL or navigation
  • 404 response: A 404 Not Found error is thrown
  • Guard chain stops: Subsequent guards are not evaluated
  • Hidden from navigation: The route does not appear in sidebars or command palette
  • No redirect: The user stays on the current page or sees the error boundary

Basic Usage

Conditional Access Control

Most commonly used with conditional logic to hide routes from unauthorized users:

Common Use Cases

Role-Based Access

Feature Flag

Hide features that are disabled:

Plan-Based Features

Hide premium features from free users:

Permission-Based Access (Async)

When to Use hidden() vs redirectTo()

Use hidden() when:

  • The route should appear to not exist for unauthorized users
  • You want to prevent route discovery through URL guessing
  • The user should not know the feature exists (e.g., beta features, premium features)
  • Access is based on roles, permissions, or feature flags

Use redirectTo() when:

  • The user needs authentication (redirect to login)
  • You want to guide users to the correct page (e.g., redirect to dashboard)
  • The route exists but requires a specific state (e.g., onboarding incomplete)

Example: Combined Guards

Effect on UI

When a route is hidden: The route will not appear in sidebar menus:

Command Palette

Hidden routes are excluded from command palette search results.

Direct URL Access

Attempting to navigate directly to a hidden route shows a 404 error.

Return Value

hidden() returns a GuardResult object:
This object is processed by AppShell’s routing system to throw a 404 error.

Error Handling

The 404 error can be caught by error boundaries:

See Also