如果文件不同,则子模块的路由未加载

时间:2014-11-10 10:57:34

标签: angularjs playframework requirejs angular-ui-router webjars

我正在使用带有RequireJS和ui-router的AngularJS,以及Play Framework 2.3(以及WebJars的东西)。

main.js

(function () {
    'use strict';

    requirejs.config({
        // Packages = top-level folders; loads a contained file named 'main.js"
        packages: ['dashboard'],
        paths: {
            'angular': ['../lib/angularjs/angular'],
            'angular-ui-router': ['../lib/angular-ui-router']
        },
        shim: {
            'angular': {
                exports: 'angular'
            },
            'angular-ui-router': {
                deps: ['angular'],
                exports: 'angular'
            }
        }
    });

    require(['angular', 'angular-ui-router', './app'],
        function (angular) {

            var mod = angular.module('app', ['ui.router']);

            mod.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', function ($stateProvider, $locationProvider, $urlRouterProvider) {
                $locationProvider.html5Mode(true).hashPrefix('!');
                $urlRouterProvider.otherwise('/app/profile');
                $stateProvider.state('profile', {
                    abstract: true,
                    url: '/app/profile',
                    templateUrl: '/views/app/content',
                    controller: 'AppController'
                });
            }]);

            angular.bootstrap(document, ['app']);

        });

})();

app.js

define(['angular', 'dashboard'], function(angular) {
  'use strict';

  return angular.module('app', ['app.dashboard']);
});

仪表板/ main.js

define(['angular', './routes'], function(angular) {
  'use strict';
  return angular.module('app.dashboard', ['dashboard.routes']);
});

仪表板/ routes.js

define(['angular'], function(angular) {
  'use strict';

  var mod = angular.module('dashboard.routes', []);
  console.log("Enter the routes.js"); // DOES WORK
  mod.config(['$stateProvider', function($stateProvider) {
      console.log("Enter the config file in routes.js"); // DOESN'T WORK, NEVER REACH THAT POINT
      $stateProvider.state('profile.dashboard', {
          url: '',
          templateUrl: '/views/app/dashboard'
      });
  }]);
  return mod;
});

我的子模块中定义的状态未加载,但如果我将它们放在main main.js中,它确实有效:

mod.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', function ($stateProvider, $locationProvider, $urlRouterProvider) {
    $locationProvider.html5Mode(true).hashPrefix('!');
    $urlRouterProvider.otherwise('/app/profile');
    $stateProvider.state('profile', {
        abstract: true,
        url: '/app/profile',
        templateUrl: '/views/app/content',
        controller: 'AppController'
    })
   .state('profile.dashboard', {
          url: '',
          templateUrl: '/views/app/dashboard'
   });
   ;
  }]);

所以这是关于使用RequireJS加载的问题,但我无法弄清楚出了什么问题。

有什么想法吗?感谢

0 个答案:

没有答案