Routing & Navigation
Rodando Passenger uses Angular’s standalone routing system with layout-based route organization, lazy loading, and route guards for authentication.Route Configuration
The main routing configuration is defined inapp.routes.ts:
src/app/app.routes.ts:6-136
Route Structure
The app has three main route zones:- Public (Auth)
- Fullscreen (Map)
Path:
/auth/*Protected by: guestGuard (blocks if authenticated)Routes:/auth/login- Login page/auth/signup- Registration page
Layout-based routing groups routes by visual layout. Routes under
DefaultLayoutComponent automatically get the tab bar and sidebar, while /auth/* and /map render fullscreen.Route Guards
Authentication Guard (with Auto-Refresh)
Protects private routes and attempts token refresh if expired:src/app/core/guards/auth.guard.ts:76-86
Token Refresh Logic
The guard attempts to refresh the access token before redirecting:src/app/core/guards/auth.guard.ts:38-71
Smart Refresh: The guard checks if the user is authenticated, attempts a silent token refresh if needed, and only redirects to login if refresh fails. This provides seamless UX for returning users.
Guest Guard
Prevents authenticated users from accessing auth pages:src/app/core/guards/auth.guard.ts:123-136
Child Route Guards
Protects all child routes under a parent:src/app/core/guards/auth.guard.ts:91-94
Lazy Loading
All feature modules are lazy-loaded using dynamic imports:Benefits of Lazy Loading
Faster Initial Load
Only loads code needed for the current route
Smaller Bundle Size
Splits app into smaller chunks loaded on-demand
Better Performance
Reduces memory usage and parse time
Code Splitting
Each feature gets its own JavaScript bundle
Lazy Loading Child Routes
Child routes can also be lazy-loaded:Auth Routes Example
src/app/features/auth/auth.routes.ts
Navigation Structure
Tab Navigation
The app uses Ionic tabs for primary navigation:Tab Routes (within DefaultLayoutComponent)
data.tab property is used by the layout component to highlight the active tab.
Sidebar Navigation
Secondary pages (settings, wallet, etc.) use the sidebar:DefaultLayoutComponent but are accessed via the sidebar menu.
Nested Routes
Some features have nested child routes:Trips Feature with Nested Routes
/trips→ redirects to/trips/active/trips/active→ shows active trip/trips/history→ shows trip history
Programmatic Navigation
Using Router
Components injectRouter for navigation:
Using RouterLink
In templates, userouterLink directive:
Navigation After Login
Facades typically navigate after successful operations:Example: Navigate after login
Route Data and Meta
Route Data
Routes can carry custom data:Query Parameters
Handle query params for filtering/state:Route Guards Summary
authGuardWithRefresh (CanActivate)
authGuardWithRefresh (CanActivate)
Purpose: Protects single routesBehavior:
- Checks if user is authenticated
- Attempts silent token refresh if expired
- Redirects to
/auth/login?returnUrl=...if refresh fails
canActivate: [authGuardWithRefresh]authGuardWithRefreshChild (CanActivateChild)
authGuardWithRefreshChild (CanActivateChild)
Purpose: Protects all child routesBehavior:
- Same as
authGuardWithRefreshbut applies to all children - Used on parent layout routes
canActivateChild: [authGuardWithRefreshChild]authGuardWithRefreshCanLoad (CanLoad)
authGuardWithRefreshCanLoad (CanLoad)
Purpose: Prevents lazy-loading bundle for unauthorized usersBehavior:
- Runs before loading the module code
- More efficient than
canActivatefor unauthorized users
canLoad: [authGuardWithRefreshCanLoad]guestGuard (CanActivate)
guestGuard (CanActivate)
Purpose: Blocks auth pages for authenticated usersBehavior:
- Checks if user is NOT authenticated
- Redirects to home (or
returnUrl) if already logged in
canActivate: [guestGuard] on /auth/* routesBest Practices
Use Layout Components
Group routes by visual layout for code reuse and consistency
Lazy Load Everything
Use dynamic imports for all feature routes to reduce bundle size
Guard Child Routes
Use
canActivateChild on parent to protect all children at onceHandle returnUrl
Save original URL in guards to redirect after login
Next Steps
Layouts
Learn about DefaultLayoutComponent and MapLayoutComponent
State Management
See how guards use AuthStore to check authentication