Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Created December 28, 2014 02:52
Show Gist options
  • Save frozonfreak/0537e0caeef8264b3dd2 to your computer and use it in GitHub Desktop.
Save frozonfreak/0537e0caeef8264b3dd2 to your computer and use it in GitHub Desktop.
Angularjs watching for route change
app.run(function($rootScope, $location) {
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
if ($rootScope.loggedInUser == null) {
// no logged user, redirect to /login
if ( next.templateUrl === "partials/login.html") {
} else {
$location.path("/login");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment