【问题标题】:Block navigation when client hits in address bar using angular js当客户端使用 Angular js 在地址栏中点击时阻止导航
【发布时间】:2015-08-10 14:49:47
【问题描述】:

您好,当用户在地址栏中输入/定价时,我必须停止导航 并且仅在 $location.path("/pricing") 被触发时导航

when("/pricing", {
        templateUrl: "app/components/Pricing/pricing.html",
    })

如何做到这一点?请帮帮我

【问题讨论】:

    标签: javascript jquery angularjs angularjs-routing


    【解决方案1】:

    您可以做的一件事是设置flag 并仅在标志为true 时导航,否则会阻止locationChangeStart 中的默认操作。

    yourApp.run(['$rootScope', function ($rootScope) {
      $rootScope.$on('$locationChangeStart', function (event, next, current) {
           if($location.path() == '/pricing' && !flag) 
             event.preventDefault(); // This prevents the navigation from happening
          }
        );
      }]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多