如何使用 angular-ui-router 防止某些 child 状态下的嵌套解析器?
How to prevent nested resolvers in some child states with angular-ui-router?
这里是plnkr:http://plnkr.co/edit/wfIFA01kfG1zggsPo7Q9
我有一个抽象 parent 状态 'app' 和两个 child 状态 'app.home' 和 'app.signin'。 Parent 状态必须解决一些异步问题。
app.core:
$stateProvider
.state('app', {
url: '',
abstract: true,
// has to be resolved by any child state, except app.auth
resolve: {
Something: function($http) {
// real delay
return $http.get('http://httpbin.org/delay/5');
}
}
});
app.home:
$stateProvider
.state('app.home', {
url: '/home',
views: {
'main@' : {
template: '<div>I am home page</div> <a ui-sref="app.signin">Sign in</a>'
}
}
});
app.signin
$stateProvider
.state('app.signin', {
url: '/',
views: {
'main@' : {
template: '<div>I am signin page </div> <a ui-sref="app.home">Home page</a>'
}
}
});
我想要任何 child 状态也需要 Something
,除了 app.signin
。我该怎么做?
另外值得一提的是,我没有在我的 child 状态下描述任何解析器。但他们仍然等到 parent 完成,我认为(引自 ui-router doc):
The resolve keys MUST be injected into the child states if you want to
wait for the promises to be resolved before instantiating the
children.
而且我不知道为什么 child 声明仍在解决 parent 的依赖关系。
所以想法是创建另一个抽象状态,app.signin 将依赖于该状态。这个 plunker 证明了(从你的 plunker 分叉):http://plnkr.co/edit/kpfbylbBTVX8Erm5cgoF?p=preview
(function() {
'use strict';
angular
.module('app.auth', [
'app.core'
])
.config(function ($stateProvider) {
$stateProvider
.state('app2', {
url: '',
abstract: true
})
.state('app2.signin', {
url: '/',
views: {
'main@' : {
template: '<div>I am signin page </div> <a ui-sref="app.home">Home page</a>'
}
}
});
});
})();
这里是plnkr:http://plnkr.co/edit/wfIFA01kfG1zggsPo7Q9
我有一个抽象 parent 状态 'app' 和两个 child 状态 'app.home' 和 'app.signin'。 Parent 状态必须解决一些异步问题。
app.core:
$stateProvider
.state('app', {
url: '',
abstract: true,
// has to be resolved by any child state, except app.auth
resolve: {
Something: function($http) {
// real delay
return $http.get('http://httpbin.org/delay/5');
}
}
});
app.home:
$stateProvider
.state('app.home', {
url: '/home',
views: {
'main@' : {
template: '<div>I am home page</div> <a ui-sref="app.signin">Sign in</a>'
}
}
});
app.signin
$stateProvider
.state('app.signin', {
url: '/',
views: {
'main@' : {
template: '<div>I am signin page </div> <a ui-sref="app.home">Home page</a>'
}
}
});
我想要任何 child 状态也需要 Something
,除了 app.signin
。我该怎么做?
另外值得一提的是,我没有在我的 child 状态下描述任何解析器。但他们仍然等到 parent 完成,我认为(引自 ui-router doc):
The resolve keys MUST be injected into the child states if you want to wait for the promises to be resolved before instantiating the children.
而且我不知道为什么 child 声明仍在解决 parent 的依赖关系。
所以想法是创建另一个抽象状态,app.signin 将依赖于该状态。这个 plunker 证明了(从你的 plunker 分叉):http://plnkr.co/edit/kpfbylbBTVX8Erm5cgoF?p=preview
(function() {
'use strict';
angular
.module('app.auth', [
'app.core'
])
.config(function ($stateProvider) {
$stateProvider
.state('app2', {
url: '',
abstract: true
})
.state('app2.signin', {
url: '/',
views: {
'main@' : {
template: '<div>I am signin page </div> <a ui-sref="app.home">Home page</a>'
}
}
});
});
})();