Angular transition ui-router 1.0.0rc replaced by redirection

Angular 1.6.1 and ui-router 1.0.0rc;

I am having a problem with ui-router when redirecting from one state to another.

A is TransitionRejectionregistered because it is replaced.

Transition #1 r0: Started  -> "Transition#1( 'intro'{} -> 'foo'{} )"
Transition #1 r0: <- Rejected "Transition#1( 'intro'{} -> 'foo'{} )", reason: TransitionRejection(type: 2, message: The transition has been superseded by a different transition, detail: 'bar'{"id":"uuid-1234-uuid"})
Transition #2 r0: Ignored  <> "Transition#2( 'intro'{} -> 'intro'{} )"
Transition #3 r0: Started  -> "Transition#3( 'intro'{} -> 'bar'{"id":"uuid-1234-uuid"} )"
Transition #3 r0: <- Success  "Transition#3( 'intro'{} -> 'bar'{"id":"uuid-1234-uuid"} )", final state: bar

Note: globally there is a trick, it is used for automatic control when the user does not decide when loading the state:

// state 'intro' is '/'
.config($urlRouterProvider => {
  $urlRouterProvider.otherwise('/'); 
})
.run(($transitions, $trace) => {
  $trace.enable('TRANSITION');
  $transitions.onError({}, trans => trans.router.stateService.go('intro'));
}

Transition Fragment

// there is no foo component, it a straight redirect
.component('bar', {
  template: someTemplate,
  controller: someCtrl
})
.config($stateProvider => {
  let states = [
    {
      name: 'foo',
      url: '/foo',
      redirectTo: { state: 'bar', params: { id: 'uuid-1234-uuid' } }
    },
    {
      name: 'bar',
      url: '/bar/:id',
      component: 'bar'
    }
  ];

  states.forEach(s => $stateProvider.state(s));
})

While in this example intro -> fooit ends up in the correct state bar, other transitions (if not from intro(default)to bar, but from baz, qux, ..to bar) end up in an infinite transitional cycle.

, qux foo, bar, qux -> intro: ( qux -> foo, )

TransitionRejection(type: 2, message: The transition has been superseded by a different transition, detail: Transition#2704( 'qux'{} -> 'intro'{} ))

- , catch-all? , -, .

+4
2

, , . . , .

 $timeout(function(){
   $state.go('statename')
})

. - , , .

+4

stateService.go, , ui-router .

0

Source: https://habr.com/ru/post/1671749/


All Articles