根据服务中的逻辑,我会路由到不同的 View 。为了促进服务注入(inject),我使用加载 Controller 来确定下一步要去哪里。
这非常有效,只是我无法通过加载 Controller “返回”。如何检测后退按钮,或修复我的加载模型以使其更友好?
.when('/loading', {
templateUrl: '/app/views/mystuff/loading.html',
controller: 'LoadingController'
})
angular.module('app').controller('LoadingController', ['$location', 'WhereService',
function ($location, WhereService) {
if (!WhereService.doneWithA()) {
$location.path('/a');
}
else if (!WhereService.doneWithB()) {
$location.path('/b');
}
else {
location.href = "/myapp/somewhereelseentirely"//this is fine
}
}]);
angular.module('app').controller('ALoadingController', ['$location', 'AService',
function ($location, AService) {
if (!AService.isDone()) {
$location.path(AService.currentPath());
}
else {
$location.path('/');//triggers loading controller above
}
}]);
最佳答案
听起来你需要$location.replace()
:
If called, all changes to $location during current $digest will be replacing current history record, instead of adding new one.
关于javascript - 通过加载 Controller 保持后退按钮的 Angular ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31654997/