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();
});