如何使用onEnter钩子和$ transition $阻止默认动作? (新的ui路由器)

时间:2021-09-29 10:51:03

I'm using ui-router 1.0.0-alpha.5. Old events are deprecated there.

我正在使用ui-router 1.0.0-alpha.5。旧事件在那里被弃用。

so I'm trying to convert

所以我想转换

$rootScope.$on('$stateChangeStart', ($event) => {
  //some logic
 $event.preventDefault();
});

into:

成:

$transitions.onEnter({}, ($transition$) => {
  //...
});

how could I prevent default action from here?

我怎么能防止这里的默认动作?

1 个解决方案

#1


5  

Looks like I found the answer:

看起来我找到了答案:

$transitions.onEnter({}, ($transition$) => {
  return $q.reject()
});

i.e. you need to return rejected promise.

即你需要退回被拒绝的承诺。

#1


5  

Looks like I found the answer:

看起来我找到了答案:

$transitions.onEnter({}, ($transition$) => {
  return $q.reject()
});

i.e. you need to return rejected promise.

即你需要退回被拒绝的承诺。