Z
Z
zagamay_ru2015-12-07 17:37:57
JavaScript
zagamay_ru, 2015-12-07 17:37:57

Angular ui.router doesn't fire controller: '' and templateUrl: ''?

Hello!
I just started learning angularjs, I
ran into the problem of building a url for localization,
for example:
/ru/
/en/
/en/about/
/en/contacts/

Worth
angularjs 1.4.8
ngRouter 1.4.8
ui-router 0.2.15
The router itself

module.exports = App.Angular
  .config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
    function($stateProvider, $urlRouterProvider, $locationProvider) {
      $locationProvider.html5Mode(true);
      
      $urlRouterProvider.otherwise('/' + App.Lang + '/');

      $stateProvider
        .state('root', {
          url: '/{lang:ru|en|de}',
          abstract: true,
        })

        .state('root.home', {
          url: '/',
          templateUrl: '/frontend/app/template/index.php',
          controller: 'MainController',
        })
        
        .state('root.home.about', {
          url: 'about/',
          templateUrl: '/frontend/app/template/about.php',
          controller: 'AboutController'
        });

    }
  ]);

Everything seems to be logical, at the URLs /ru/, /en/, /de/ the MainController controller should be launched and the /frontend/app/template/index.php template should be rendered, but nothing happens, the console is silent.
.state('home', {
          url: '/{lang:ru|en|de}/',
          templateUrl: '/frontend/app/template/index.php',
          controller: 'MainController',
        })
        .state('home.about', {
          url: 'about/',
          templateUrl: '/frontend/app/template/about.php',
          controller: 'AboutController'
        });

I tried to register it this way, only the main one works, and when you go to /ru/about/, the url changes, but the controller works in state HOME, I don’t understand how to set it up correctly, please tell me.
it seems that they are all inherited, not only urls, but also cntr, templates
PS Don't throw it on the manual, I don't know English =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zagamay_ru, 2015-12-07
@zagamay_ru

Found a solution, added template: '' and specified the template with the controller through views

$stateProvider
      .state('root', {
        url: '/{lang:ru|en|de}',
        abstract: true,
        template: '<div ui-view></div>'
      })
      .state('root.home', {
        url: '/',
        views: {
                '': {
                    templateUrl: '/frontend/app/template/index.php',
                    controller: 'MainController'
                }
            }
      })
      .state('root.about', {
        url: '/about/',
        views: {
                '': {
                    templateUrl: '/frontend/app/template/about.php',
                    controller: 'AboutController'
                }
            }
      });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question