需要一些关于将我的 ngRoute 配置迁移到 ui.router 配置的指导。目前我有一个主模板(index.html),它有一个注入所有视图的 ng-view。我当前的 ngRoute 配置如下:
app.config(function ($routeProvider) {
$routeProvider
.when('/login', {
templateUrl: 'app/views/login.html',
controller: 'LoginCtrl'
})
.when('/contact', {
templateUrl: 'app/views/contact.html',
controller: 'ContactCtrl'
})
.when('/notification', {
templateUrl: 'app/views/notification.html',
controller: 'NotificationCtrl'
})
.otherwise({
redirectTo: '/login'
});
我现在想在 index.html 中定义第二个位置,我可以在其中注入一些视图内容——不是嵌套视图,而是另一个 ng-view(或 ui-router 术语中的 ui-view)。原始的 ng-view 部分是默认部分(目前仅用于 /login 和 /contact),而新部分仅用于特定路由(当前仅 '/notification' 但将来可能还有其他)。让我们将新的 ui-view 称为“通知视图”。
我已经阅读了大部分 ui-router 文档,但仍然不确定如何将上述内容迁移到新的 ui.router 配置。有人可以让我开始或指出一些像样的例子吗?
更新:好的,这就是我的位置。我在 index.html 页面中添加了一些状态和新的 ui 视图。见下文:
<div class="container">
<div id="header"></div>
<div data-ui-view></div>
<div data-ui-view="notification-view"></div>
</div>
我的路由现在是:
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'app/views/login.html',
controller: 'LoginCtrl'
})
.state('contact', {
url: '/contact',
templateUrl: 'app/views/contact.html',
controller: 'ContactCtrl'
})
.state('notification', {
url: '/notification',
views: {
"notification-view": {
templateUrl: 'app/views/notification.html',
controller: 'NotificationCtrl'
}
}
});
});
这似乎在大多数情况下都可以正常工作。当 url/notification
被触发时,应用程序被路由到 NotificationCtrl 并将 ui-view 内容呈现到notification-view
. 然而,唯一的问题是主(未命名)ui 视图中的 ui 内容丢失了。我希望主 ui 视图中已经呈现的任何内容都保持不变,并且只针对notification-view
. 这可能吗?它是否必须改为嵌套视图?