2015-08-02 5 views
3

Я пытаюсь открыть состояние 'profile.general' по умолчанию, когда я перехожу к профилю состояния родителя, который загружает основной шаблон.По умолчанию Угловой UI-Router Nested View

Как активировать вложенное состояние для ui-view при навигации по URL-адресу/profile?

$urlRouterProvider.otherwise("/profile/general"); 

$stateProvider.state('profile', { 
    url: '/profile', 
    abtract: true, 
    views: { 
     "main": { 
      controller: 'ProfileCtrl', 
      templateUrl: 'src/app/profile/index.tpl.html' 
     } 
    } 
}).state('profile.general', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-general.html' 
    //controller: 'ProfileCtrl' 
}).state('profile.security', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-security.html' 
}).state('profile.social', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-social.html' 
}).state('profile.privacy', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-privacy.html' 
}).state('profile.payments', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-payments.html' 
}).state('profile.restrictions', { 
    //url: '/register/details', 
    templateUrl: 'src/app/profile/profile-restrictions.html' 
}); 
}) 

HTML

<div id="profile-views" ui-view></div> 
+0

для profile.general набора url будет '' '' пустым – mohamedrias

ответ

3

Существует a working plunker

Эти линии должны помочь:

$urlRouterProvider.when("/profile", "/profile/general"); 
$urlRouterProvider.otherwise("/profile/general"); 

И мы должны дать url к общему югу состояние:

.state('profile.general', { 
    //url: '/register/details', 
    url: '/general', 
    templateUrl: 'src/app/profile/profile-general.html' 

Так, с этим на месте, у нас есть .when Перенаправление ... что всякий раз, когда пользователь таргетингом только абстрактное состояние - это перенаправлять на выбранный URL.

Кроме того, поскольку мы ввели url для ребенка, мы можем использовать .otherwise как общее состояние по умолчанию.

Другой способ, как сделать это, чтобы опустить URL одного ребенка (только точно один ребенок):

How to: Set up a default/index child state

Проверить это here

Смежные вопросы