2013-05-17 31 views
2

在初始化应用程序时在第一页加载我想将用户重定向到登录页面。我想代码的相关部分是这个在angularjs中初始化应用程序时重定向

$rootScope.$on("$routeChangeStart", function (event, next, current) { 
    alert("change location"); 

    $location.path('/login'); 
}); 

它是基于https://github.com/fnakstad/angular-client-side-auth/blob/master/app/js/app.js的问题是在页面载入触发警报,但位置不会改变。我必须点击我的应用程序的导航项目,然后登录操作将被调用,并且路线更改。

.run(['$rootScope', '$location', '$cookieStore', function ($rootScope, 
                $location, $cookieStore) { 

    $location.path('/login'); 

    $rootScope.$on("$routeChangeStart", function (event, next, current) { 

     $location.path('/login'); 

    }); 

    $rootScope.appInitialized = true; 
}]); 

这样会起作用,但看起来多余。为什么警报被触发,而不是位置更改?

为什么位置在整页加载时不会改变?如何解决这个问题?

的完整代码http://jsfiddle.net/qfSC3/但小提琴不起作用。

回答