I'm building a web/phonegap application for an older version of Android (2.3.x). Everything works great up until I try to add any server redirection into the mix. Here's the scenario:
The server (node.js) has a route listening at '/'. When this route is hit, it checks to see if the there is a session or not. If there is no session, it redirects to /login. Fine, this part works (server wise, anyways).
The problem arises when the client gets the redirect. Because Android 2.3 doesn't support history.pushState, it falls back to hashbangs. This means AngularJS rewrites the url to /#!/login, which causes a server request to '/', which causes the server to check session and redirect to '/login', which causes AngularJS to rewrite the url to /#!/login.. and so on and so forth.. indefinitely.
Any ideas how I can redirect from the server with AngularJS? Should I not be handling this logic in my route but instead try to implement it on the client? There has to be a way to handle this, I'm sure, but I just can't seem to figure it out.
Any help would be greatly appreciated. Thanks!!
Use a simple object for commanding redirects:
If the user is not logged in, return {action: "redirect" url:"/login"}
Then in client, after getting the response, check for action == 'redirect'
and $location.path(url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With