引用另一个模块时出现路由冲突

时间:2016-08-10 00:49:30

标签: angularjs angular-ui-router

考虑以下代码

angular.module('module1', []).
config(["$stateProvider", "$urlRouteProvider", function($stateProvider){
    $urlRouteProvider.when('', 'Profile');
    $stateProvider.state('Profile', {
        url: '/Profile',
        templateUrl: '/path/to/template'
        controller: 'controller as ctrl'
    }
}]).
service('IWantToUseThisServiceInModule2', serviceFunction);

angular.module('module2', ["module1"]).
config(["$stateProvider", "$urlRouteProvider", function($stateProvider){
    $urlRouteProvider.when('', 'Profile');
    $stateProvider.state('Profile', {
        url: '/Profile',
        templateUrl: '/path/to/template'
        controller: 'controller as ctrl'
    }
}]);

我试图引用module2中的module1来使用module1中的服务。但是,我得到了状态' Profile'已经定义了。我可以通过将profile中的Module2状态更改为任何其他状态来解决此错误。现在我没有收到错误但是当一条路线不存在时,我仍然会被路由到Profile州。我知道这种情况正在发生,因为依赖关系首先被初始化。有办法解决吗?我希望Module2中的路线优先。

由于

0 个答案:

没有答案
相关问题