How to set default child view with Angular UI Router

后端 未结 3 1847
忘了有多久
忘了有多久 2020-12-16 10:03

Let\'s say I have the following 3 Angular UI Router states:

$stateProvider
    .state(\'adminCompanies\', {
        abstract: true,
        url: \"/admin/com         


        
3条回答
  •  遥遥无期
    2020-12-16 10:42

    In version 1.0.0alpha0 they finally make it possible! Not child for abstract states, new $transitionsProvider, in which you could define onBefore hook. You can change the behaviour depends on state options.

    For example you can change "abstract" param behaviour:

     $transitionsProvider.onBefore({
        to: state => !!state.abstract
      }, ($transition$, $state) => {
        if (angular.isString($transition.to().abstract)) {
          return $state.target($transition.to().abstract);
        }
      });
    

    and use it like so:

      abstract: 'abstract2.foo',  //use not boolean but exact child state
    

    code example

    was taken from: ui-router: Default child for abstract state

提交回复
热议问题