【发布时间】:2018-10-11 22:21:32
【问题描述】:
在我的应用程序的 $stateProvider 上,我定义了应用程序的所有状态:
+ function () {
"use strict";
function cataneiConfig($stateProvider, $urlRouterProvider, $httpProvider) {
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'views/login.html',
controller: 'loginCtrl as $ctrl'
})
.state('layout', {
url: '/layout',
views:{
'':{//Default layout
templateUrl: 'views/layout.html',
controller: 'layoutCtrl as $ctrl'
},
'list@layout':{
templateUrl: 'views/list.html',
controller: 'listPersonaCtrl as $ctrl'
},
'form@layout': {
templateUrl: 'views/form.html',
controller:'createPersonaCtrl as $ctrl'
},
'edit@layout':{
params: { obj: null },
templateUrl: 'views/edit.html',
controller:'editPersonaCtrl as $ctrl'
}
},
})
.state('error', {
url: '/error',
templateUrl: 'views/error.html'
});
$urlRouterProvider.otherwise('login');
}
cataneiConfig.$inject = [
"$stateProvider",
"$urlRouterProvider",
"$httpProvider",
];
angular
.module("appTareas")
.config(cataneiConfig);
}();
从 login 控制器 ===> $state.go('layout') 工作并重定向到 layout.html... .如预期的那样。
来自 layout.html ===> <ui-view ='list'/> 在 layout 状态下正确显示 list.html。
来自 list 控制器 ===> $state.go('form') 或 $state.go('edit') , 不工作。在 list.html 中 <a ui-sref='form'/> 不起作用。
如何在不同视图及其控制器之间进行重定向?
【问题讨论】:
-
我假设你已经看过这个,但如果没有,here is a sample app doing what you are trying to achieve
-
@Tyler 是的,但他们使用了不同的逻辑。他们使用高级组件,我只需要在 $stateProvider 中使用简单的方法,并且如果可能的话使用 $state
标签: angularjs angular-ui-router viewstate ui-sref state.go