首页 > ui-router中如何使用onEnter,onExit方法来控制视图访问

ui-router中如何使用onEnter,onExit方法来控制视图访问

代码:

onEnter:function(){
                    var v = confirm("are you sure to continue?");
                    if(!v){
                        console.log("here");
                        return false;
                    }
                },
                onExit:function(){
                    var v = confirm("are you sure to exit?");
                    if(!v){
                        console.log("here");
                        return false;
                    }
                }

我的控制台确实输出了,但是还是跳转视图了
下面是效果,
https://gyazo.com/fd2a8a0dd7832f2024869860b5277df3


如果但是判断跳转条件的话,可以在响应点击函数中添加判断

controller('ctrl', function($scope){
    $scope.foo=function(e);
    
    if(....){
        e.preventDefault();
    }
}

视图跳转是状态控制的,你把html模板上的ui-sref那个状态去掉不就好了,就不能跳了呀。

【热门文章】
【热门文章】