0

I've been digging through the $location.path postings for the past few hours, with no success. I think this example is really close, but I can't find what I'm missing.

$location.path() calls are returning my current path the first time they are clicked, then undefined. When I try to route with $location.path('/') nothing happens.

I have a soft button, bound to $rootScope.backBehavior that works correctly in iOS, but the below binding for Android doesn't work. I've tried doing an $injector.get('$location'); as well but I get the same behavior.

    $rootScope.backBehavior = function() {
        console.debug("Back button pressed for path: " + $location.path());
        //For certain pages we navigate to home page on back button
        var homeRoutes = ['contactus', 'aboutus'];
        $.each(homeRoutes, function( index, value ) {
            if($location.path() == ('/'+value)) {
                console.debug("change path to: /");
                $location.path('/');
                return;
            }
        }); 

        var backDisabled = ['mustDoSomething'];
        $.each(backDisabled, function( index, value ) {
            if($location.path() == ('/'+value)) {
                console.debug("Back button disabled for route: " + value);
                return;
            }
        }); 

        if($location.path() == '/complexRoute'){
            console.debug("Change route to: /anotherPath");
            $location.path('/anotherPath');
            return;
        } 

    };

    // Android back button support
    WL.App.overrideBackButton(function(){
        $rootScope.backBehavior();
    });
Idan Adar
  • 44,156
  • 13
  • 50
  • 89

1 Answers1

0

It looks like this is the same issue here: Angular $location.path not working

  1. Try to run the expression as function in the $apply() method:

    $rootScope.$apply(function() {

    $location.path("/");        
    

    });

  2. Try to use $location.replace() after changing the $location.path .

Community
  • 1
  • 1
Shmulik Bardosh
  • 299
  • 1
  • 6