$stateProvider
.state('feed', {
url: '/feed'
...
resolve: {
'feedData': function() {
return 'foo';
}
}
})
.state('feed.detail', {
url: '/feed/:itemId'
...
resolve: {
'singleFeedData': function(feedData) {
return feedData; // the inherited resolve.
}
}
})angular.module('main', ['main.contacts', 'ui.router'])
.config(function($stateProvider) {
$stateProvider.state('main', {...})
});
angular.module('main.contacts', ['ui.router'])
.config(function($stateProvider) {
$stateProvider.state('main.contacts', {
...
})
});$scope.$on('$stateChangeError', function(event, toState, ... , error) {
// catch errors from resolves in here!
});(with Authentication)
$stateProvider.state('admin', {
url: '/admin',
data: {
pageTitle: 'Admin Console',
requiresAuth: true
}
...
})
$scope.$on('$stateChangeStart', function(event, toState, toParams... )
// check authentication in your "auth service".
if (toState.data.requiresAuth && !AuthService.isAuthenticated()) {
$state.transitionTo('login');
event.preventDefault(); // stop state transition
}
});
<header ui-view="header"></header>
<nav ui-view="switcher"></nav>
<div ui-view="menu" autoscroll="false"></div>$stateProvider.state('home', {
url: '/home',
data: { pageTitle: 'Home' },
views: {
'main': {
templateUrl: 'home/home.tpl.html'
}
}
})
.state('home.confirm', {
url: '/confirm',
data: { pageTitle: 'Confirm' },
views: {
// target and override the named view "main" in the parent state
'main@': {
templateUrl: 'home/confirm.tpl.html'
}
}
});
"Can lead to anti-patterns"
- @timkindberg

// cannot activate this state directly.
.state('parent', { url: '/home', abstract: true })
// ALSO url '/home', overriding its parent's activation
.state('parent.list', { url: '', abstract: true })because everyone loves animations.
<a ng-class="{ active: $state.includes('app.dashboard')}" ui-sref="app.dashboard">Dashboard</a>
url: '/{userId:[0-9]{1,4}}',