在许多 angular UI-路由器状态中重复使用 URI

Re-use URI in many angular UI-Router state

我试图通过 angular UI-Router 为多个状态重新使用 url。

我试过这样做:

.state('app.contracts', {
    url: '/contracts',
    controller: function($rootScope, $scope, $state) {
        if ($rootScope.isDistributor) {
            $state.go('app.contracts-distributor');
        } else if ($rootScope.isShop) {
            $state.go('app.contracts-shop');
        } else if ($rootScope.isVendor) {
            $state.go('app.contracts-vendor');
        }
    }
})
.state('app.contracts-distributor', {
    controller: 'ContractDistributorController',
    templateUrl: 'views/contracts/list-distributor.html'
})
.state('app.contracts-shop', {
    controller: 'ContractShopController',
    templateUrl: 'views/contracts/list-shop.html'
})
.state('app.contracts-vendor', {
    controller: 'ContractVendorController',
    templateUrl: 'views/contracts/list-vendor.html'
})

但是当我尝试这个时,我遇到了一个无限循环。

知道我做错了什么吗?

a working plunker

不确定这个概念,真正的目标是什么......但它应该有效。这是调整后的状态(只是为了去别的地方):

.state('app', { template: '<div ui-view=""></div>', })
.state('app.contracts', {
  url: '/contracts',
  controller: ['$rootScope', '$scope', '$state',
    function($rootScope, $scope, $state) {

    if ($rootScope.isDistributor) {
      $state.go('app.contracts-distributor');
    } else if ($rootScope.isShop) {
      $state.go('app.contracts-shop');
    } else { // if ($rootScope.isVendor) {
      $state.go('app.contracts-vendor');
    }
  }]
})

我使用了数组控制器表示法和 ng-strict-di,只是为了避免以后出现缩小问题。 并保证,父状态应用程序有目标 ui-view=""

检查一下here