gpt4 book ai didi

javascript - 在 UI-Router 中调用子状态时触发无限循环

转载 作者:行者123 更新时间:2023-11-27 23:40:59 25 4
gpt4 key购买 nike

我在 UI-Router 的父 Controller 中有以下配置。

$stateProvider.state('store', {
abstract: true,
url: '/:store',
resolve: {
Store : ['StoreService', '$stateParams', '$state', '$rootScope', function (StoreService, $stateParams, $state, $rootScope) {

return StoreService.getStoreByCode($stateParams.store).then(
function (response){
$rootScope.Store = response.data;
return response.data;
},
function (response){
$state.go('store.404', $stateParams);
}
);
}]
},
templateUrl: 'app/app.html'
});

然后在子配置中我有:

$stateProvider
.state('store.404', {
parent:'store',
url: '/store.404',
template: '<h1>Whoa! 404!</h1>'
});

问题是,当resolve语句中的promise被拒绝时,$state.go('store.404')会触发无限循环并使浏览器崩溃。

这是因为父级每次尝试进入子级状态时都在加载和解析吗?有没有一种干净的方法可以不在子状态上触发该解析语句?

最佳答案

...Is this because the parent is loading and resolving every time it tries to go to that child state?

是的。

...Is there a clean way to not have that resolve statement trigger on the child state?

没有

解决方案是 - 像“404”这样的状态应该是单独的,特殊的。这样,它将始终可用,没有任何限制或错误处理。

即- 将“404”状态移至任何父级之外。

关于javascript - 在 UI-Router 中调用子状态时触发无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com