Built-in Permission System
The router includes a flexible permission system for implementing role-based access control (RBAC). Protect routes, control navigation, and conditionally show/hide UI elements based on user permissions.
Configuration
Configure the permission system once in your main.js before mounting your app:
Protecting Routes
Use createProtectedRoute() to protect routes with permissions - no wrap() needed!
ANY Permission (OR Logic)
User needs at least ONE of the specified permissions:
ALL Permissions (AND Logic)
User needs ALL of the specified permissions:
Advanced: Using wrap() with createProtectedRouteDefinition()
For more control or when combining with other wrap options, use createProtectedRouteDefinition() with wrap():
Controlling UI Elements
Use hasPermission() to show/hide UI elements based on permissions:
Permission Requirements
ANY (OR Logic)
any: [...]
User needs at least ONE of these permissions.
ALL (AND Logic)
all: [...]
User needs ALL of these permissions.
Practical Examples
Complete Permission Setup
Route Configuration
Navigation with Permissions
Feature Flags with Permissions
Custom Permission Logic
You can implement complex permission checks in your checkPermissions function:
Best Practices
Configure Early
Configure permissions in main.js before mounting your app to ensure the system
is ready when routes are accessed.
Granular Permissions
Use specific permission names like users.read, users.write instead
of broad permissions like admin for better control.
Server-Side Validation
Client-side permissions are for UX only! Always validate permissions on the server for security. Never trust client-side checks alone.
Unauthorized Handler
Always implement an onUnauthorized handler to gracefully handle
unauthorized access attempts.
Integration with Authentication
Combine permissions with your authentication system:
Try It Live
See the permission system in action:
Check out the example-permissions/ directory in the repository for a complete
working example with mock authentication and role-based access control.