通过加载控制器在 angular 中保留后退按钮?

Preserving back button in angular through a loading controller?

根据服务中的逻辑,我路由到不同的视图。为了方便服务注入,我使用加载控制器来确定下一步去哪里。

这很好用,只是我无法 "back" 通过加载控制器。我如何检测后退按钮,或修复我的加载模型以使其更友好?

    .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.

https://docs.angularjs.org/api/ng/service/$位置