I am using angular-ui-router and nested states in my application, and I also have a navigation bar. The nav bar is hand written, and uses ui-sref-active
to high
UI router. Code snippet to make your navigation bar active.
HTML
<li ui-sref-active="is-active" ui-nested><a ui-sref="course">Courses</a>
</li> <li ui-sref-active="is-active" ui-nested><a ui-sref="blog">blog</a></li>
CSS
is-active{
background-color: rgb(28,153,218);
}
Inside courseView.HTML
<button type="button" ui-sref="blog" class="btn btn-primary">Next</button>
This button is present inside course View which navigate you to next View i.e blog. and makes your navigation bar highlighted.
find similar example, a demo angular ui-router app: https://github.com/vineetsagar7/Angualr-UI-Router
Here what I did to achieve the same. Parent state is "app.message" and do not declare as abstract.
Children states are "app.message.draft", "app.message.all", "app.message.sent".
My Nav Link -
<a ui-sref-active="active-menu" ui-sref="app.message">Messages</a>
Define your children routes/links.
and update in config-
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
if (toState.name === 'app.message') {
event.preventDefault();
$state.go('app.message.draft');
return;
}
});