I am using a very simple interceptor to check the response, to redirect users to login Rejected for 403 access, but this redirect can correct console.log before and after that line $ location.path, and it never happens. Has anyone else had this happen? I'm staring at it for a while ... Originally I did not want to use the $ location, but I could not inject ui.router without getting a circular dependency, which I do not even know That was how I should have moved to get rid of this way $, while I had thought about it.
.factory ('AuthInterceptor', ['$ q', '$ location', function $ Q, $ location] {var service = {responseError: function (responseRejection) {// authorization Problem, if access forbidden (responseRejection.status === 403) {// TODO: Show a login dialog, and / or redirect login console.log ("responses rejected ... redirecting to login ... ") $ location.path ('/ login'); $ Location.replace (); Console.log ("not so much with redirection ... I am still here"); // send an error message to any infected wired handlers; return $ q.reject (responseRejection); }} Return service; }]
When using location.href
It sets the location immediately and stops execution of the script, but the location change will only take effect when the current script path will be completed under execution. This is the reason that you see that the statement below the ARAR is executed. This is not a blocked activity (as opposed to an alert or prompt). When setting the location using a chonal ripper, it will be effective after the digest cycle. And in the $ state
in $ http
you have a valid issue of circular dependency while injecting the interceptor, you can see the example of $ state
You can get it by using the $ injector. .factory ('AuthInterceptor', ['$ Q', '$ injector', function ($ q, $ injector) {var $ state; var service = {responseError: function Response) {// Authorization problem, if restricted entry (responseRejection.status === 403) {// TODO: Show a login dialog, and / or redirect to login.log ("reply denied. Redirecting to login ... "); _setState ('login'); console.log (" not so much with redirection ... I am still here ") //} The error messages return $ q.reject (responseRejection) to any chained futures handlers;}} _setState (stateName) {if (! $ State) {$ injector.get ('$ state'); // or just $ injector Receive $ state from always there are singing dependency containers and service anyway Letons} $ state.go (statename);} return service;}]);
Comments
Post a Comment