Coder Social home page Coder Social logo

Comments (8)

fnakstad avatar fnakstad commented on July 30, 2024

Hi there, and thanks for checking out my code :)

The $routeChangeStart event actually also triggers on the initial page load after Angular has boostrapped the app.

Definitely check out the live deployment: http://angular-client-side-auth.herokuapp.com/
There you will notice that it will redirect you to the login page right away even though the URL I just posted in this comment points to the root. Same thing happens if you try to go straight to /admin or some other restricted route.

from angular-client-side-auth.

artworkad avatar artworkad commented on July 30, 2024

Well in my app this is not the case. The route change is not triggered on page load and I use exactly your code. I had to do

$location.path('/login');

$rootScope.$on("$routeChangeStart", function (event, next, current) {      
     $location.path('/login');        
});

This works. very strange. I have asked a question regarding this problem on SO http://stackoverflow.com/questions/16605199/redirect-when-app-is-initialized-in-angularjs

from angular-client-side-auth.

fnakstad avatar fnakstad commented on July 30, 2024

Hmmm, that's quite strange... Do you get the same behaviour when visiting http://angular-client-side-auth.herokuapp.com/? Do you get any error messages in the console of Chrome Developer Tools/Firebug when loading the page?

from angular-client-side-auth.

fnakstad avatar fnakstad commented on July 30, 2024

Perhaps you could make a jsFiddle where you reproduce the problem? That would make it a lot easier to debug for me :)

from angular-client-side-auth.

artworkad avatar artworkad commented on July 30, 2024

No there are no error in console. I've setup a fiddle http://jsfiddle.net/Edsvt/ But it is not working, not sure why. However it show describe my code quite well.

from angular-client-side-auth.

Kahramon avatar Kahramon commented on July 30, 2024

Hello,

is the problem not somewhere in app the configuration.. try with commenting the code below if you have:
app.use(app.router);

from angular-client-side-auth.

fnakstad avatar fnakstad commented on July 30, 2024

I copied the jsFiddle code to my local machine, and played around with it a little bit. I was a little puzzled at first too, since there were no reported errors, the run function seemed to work, and though the $routeChangeStart handler was successfully registered on the $rootScope it was never fired. However, the reason is quite simple: You do not have an ngView attribute in your HTML, so the $route service didn't know where to render your templates and thus handle route changes. Read more about ngView here: http://docs.angularjs.org/api/ng.directive:ngView

from angular-client-side-auth.

JPVenson avatar JPVenson commented on July 30, 2024

http://docs.angularjs.org/api/ng.directive:ngView is Offline and i the JsFiddle is also not working on my maschine and angular build (v1.5.8)

from angular-client-side-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.