UI 中的多个过渡钩子 glob AngularJS 1.6 中的路由器

Multiple transition hook globs in UI Router in AngularJS 1.6

我创建了一个钩子来在更改页面之前执行一个函数,但我只需要为某些页面执行这个钩子。

我在文档中找到了这个:

$transitions.onBefore({ from: 'liste.**'}, function (transition) {
        //code to execute when  the page belongs to 'liste' route
    });

但是我需要指定更多的路由。

我该怎么做?

例如:

$transitions.onBefore({ from: 'liste.**', from: 'demand.**'}, function (transition) {
        //code to execute when  the page belongs to 'liste' route
    });

那是我尝试过的方法,但我有一个错误,所以我认为这不是一个好方法。

谢谢

我自己找到了解决方案:

$transitions.onBefore({ from: ['liste.**','demande.**']}, function (transition) {
    //code to execute when  the page belongs to 'liste' route
}); 

只需将 'from' 更改为数组