1

把案例我有一条路线

.config(function (CONFIG,$routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: CONFIG.site.path_views + '/index/index.html',
                controller: 'IndexCtrl'
            })
            .when('/contestant/create', {
                templateUrl: CONFIG.site.path_views + '/contestant/create.html',
                controller: 'ContestantCreateCtrl'
            })
            .when('/contestant/thanks', {
                templateUrl: CONFIG.site.path_views + '/contestant/thanks.html',
                controller: 'ContestantThanksCtrl'
            })
            .when('/product', {
                templateUrl: CONFIG.site.path_views + '/product/index.html',
                controller: 'ProductCtrl'
            })
            .when('/prize', {
                templateUrl: CONFIG.site.path_views + '/prize/index.html',
                controller: 'PrizeCtrl'
            })
            .otherwise({
                redirectTo: '/'
            });

    })

如果他/她已填写表格,我想拒绝访问或简单地将用户重定向到 /contestant/create 但我没有找到方法:(

4

1 回答 1

0
app.run( function(VisitedRoutes) {
    VisitedRoutes.init();
};
app.factory('VisitedRoutes', function($rootScope,$location) {
        var routes = [];
        return {
            add : function(){
                 routes.push($location.path());
            },
            all:function(){
                return _.uniq(routes);
            },
            hasRoute:function(value){
               return _.indexOf(this.all(), value) 
            },
            init:function(){
                var that = this;
                $rootScope.$on('$routeChangeSuccess', function (scope, next, current) {
                    that.add();
                });
            }
        }
    });
app.controller('ContestantCreateCtrl',function($scope,$location,VisitedRoutes) {
    if(VisitedRoutes.hasRoute('/contestant/thanks') !== -1){
        $location.path('/');
    }
});

感谢@Jesus Rodriguez :)

于 2013-10-01T14:41:09.327 回答