Navigation
UI-Router provides powerful APIs for navigating between states programmatically. This guide covers all navigation methods and options.StateService Overview
TheStateService (located at router.stateService) is the primary API for navigation:
Basic Navigation with go()
Thego() method is the recommended way to navigate:
Method Signature
Navigation Options
TheTransitionOptions object controls navigation behavior:
Location - Update Browser URL
Inherit - Parameter Inheritance
Reload - Force State Reload
Relative - Relative Navigation
Custom - Custom Data
Supercede - Control Transition Cancellation
Relative Navigation
Navigate relative to the current state using special syntax:Handling Navigation Results
Thego() method returns a promise:
stateService.go('user', { userId: 123 })
.then((state) => {
console.log('Navigated to:', state.name);
});
stateService.go('protected')
.catch((error) => {
if (error.type === RejectType.ABORTED) {
console.log('Navigation aborted by hook');
} else {
console.error('Navigation error:', error);
}
});
Low-Level Navigation with transitionTo()
For advanced use cases, usetransitionTo() directly:
- When you need full control over options
- When building custom navigation wrappers
- In low-level framework integrations
- Normal application navigation
- Default parameter inheritance
- Relative state paths
Reloading States
Force reload of the current state:Creating Target States
Create aTargetState object for advanced scenarios:
- Validation before navigation
- Redirects in transition hooks
- Building navigation history
URL-Based Navigation
Navigate using URLs via theUrlService:
URL Parts
Checking Current State
is() - Exact State Match
Check if a specific state is currently active:includes() - Hierarchical Match
Check if current state equals or is a child of a state:Generating URLs
Generate URLs for states without navigating:Accessing State Information
Current State
State Lookup
Navigation Examples
Example 1: Tab Navigation
Example 2: Pagination
Example 3: Modal Navigation
Example 4: Conditional Navigation
Example 5: Breadcrumb Navigation
Best Practices
// Good
stateService.go('user', { userId: 123 });
// Avoid unless you need low-level control
stateService.transitionTo('user', { userId: 123 }, {...});
stateService.go('dashboard')
.then(() => console.log('Navigation complete'))
.catch((error) => console.error('Navigation failed', error));
// More maintainable
stateService.go('^.sibling');
// Less maintainable - hardcoded parent name
stateService.go('parent.sibling');
Related Documentation
- State Configuration - Define states
- Parameters - Work with parameters
- Transition Hooks - Control navigation
- URL Routing - URL-based navigation
API Reference
- StateService - Navigation methods (
go,transitionTo,reload) - TransitionOptions - Navigation options
- UrlService - URL-based navigation