Jump to external links, angular ui-router disable issu

the company now has a business scenario: when entering an itil URL, you first determine whether you are logged in. If you do not log in, you need to jump to an external link login entry to log in.

now the problem is coming out!

1 when jumping to the external login link (a new tab page has been opened).
2 at this point, ui-router, will resolve the redirected external link to an incorrect route
3. When redirected to the wrong route, it will be automatically redirected to the home page
4. If you redirect the home page, you will jump to the external login link because you are not logged in yet.

will repeat the process of determining whether or not to log in, do not log in, and jump to the external link. Over and over again, the endless cycle.

 $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
        //  
        if(toState.name == "login") {
            return;
        }
        if(toState.name != "login") {
            var currentUrl = window.location.href;
            var currentState=toState.name;
            
            //
            try{
                //1.  
                var userInfo=JSON.parse($cookies.get("userInfo"));
                $rootScope.loginCode=userInfo.Code;
            }catch(err){
                console.log(err);
                event.preventDefault();
     
                 window.open="http://helloworld:6688/hello/control/main?url=http://localhost:8889/-sharp!/app/home";//

            }
        }
    });

after looking up all kinds of information on the Internet, it can"t be solved. after jumping to an external link, ui-router do not act (do not resolve the external link to the wrong route, and then jump to the home page, which leads to an endless loop) .

you can"t solve the red problem by putting a tag element in the append on the page in JS, and then triggering the click event (forcing you to simulate user behavior and jump to an external link).

I hope that the great god who is familiar with the principle of ui-router or the students who have stepped on the pit before, can help with the analysis, thank you!

Mar.13,2021

problem solved! It can be solved by deleting event.preventDefault (); from the catch statement. Specific principle, or look at the ui-router source code! The relevant documents will be updated later!

Menu