angular.module('MyApp', []) .run(function($rootScope, myLoginService) { $rootScope.$on('$routeChangeStart', function () { if (!myLoginService.isUserLoggedIn()) { $location.path('/login'); } });