Angular-ui-router: ui-sref-active and nested states

前端 未结 8 958
独厮守ぢ
独厮守ぢ 2020-12-02 10:06

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

相关标签:
8条回答
  • 2020-12-02 11:04

    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

    0 讨论(0)
  • 2020-12-02 11:04

    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;
                    }
                });
    
    0 讨论(0)
提交回复
热议问题