工作灯和角度注入$location.path('/') 方法在 android 后退按钮功能中不是路由



在过去的几个小时里,我一直在挖掘$location.path帖子,但没有成功。我认为这个例子真的很接近,但我找不到我错过了什么。

$location.path()调用在第一次单击时返回我的当前路径,然后未定义。当我尝试与$location.path('/')路由时,没有任何反应。

我有一个软按钮,绑定到在iOS中正常工作的$rootScope.backBehavior,但以下适用于Android的绑定不起作用。我也尝试过做一个$injector.get('$location');,但我得到了相同的行为。

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

看起来这是同样的问题:角度$location.路径不起作用

  1. 尝试在 $apply() 方法中将表达式作为函数运行:

    $rootScope.$apply(function() {

    $location.path("/");        
    

    });

  2. 尝试在更改 $location.path 后使用 $location.replace() 。

最新更新