角度 UI 路由器 - 嵌套路由不适用于具有嵌套状态的模板

Angular UI Router - nested routes does not work on templates with nested state

本文关键字:嵌套 状态 不适用 路由器 UI 路由 角度 适用于      更新时间:2023-09-26

这是我的代码:

.state('profile',{ 
        url : '/profile',
        templateUrl: 'views/user.html', 
        controller: 'UserCtrl'
      })
      .state('profile.forgot',{ 
        url : '/delivers',
        templateUrl: 'views/user_forgot.html', <- this template not appear, when state is active
        controller: 'forgotCtrl'
      })
<a ui-sref="profile.forgot">Forgot your pasword?</a>
<div class="panel" ui-view=""></div>

当我单击链接时,在 ui-view 中出现了父状态的模板和控制器。AngularJS版本是1.2.0-rc.2

嵌套状态将在其父模板的ui-view元素中呈现(如果没有父模板,则在根ui-view中呈现)。请务必阅读文档的"嵌套状态和视图"部分。

请注意亲子命名约定!

.state('profile.forgot',{ 
        url : '/forgot',
        templateUrl: 'views/profile.forgot.html',
        controller: 'forgotCtrl'
      })