Javascript 当客户端使用angular js点击地址栏时阻止导航

Javascript 当客户端使用angular js点击地址栏时阻止导航,javascript,jquery,angularjs,angularjs-routing,Javascript,Jquery,Angularjs,Angularjs Routing,您好,当用户在地址栏中键入/定价时,我必须停止导航 并仅在激发$location.path(“/pricing”)时导航 如何做到这一点?请帮助我您可以做的一件事是设置一个标志,并仅在标志为true时导航,否则禁止在位置更改开始中执行默认操作 yourApp.run(['$rootScope', function ($rootScope) { $rootScope.$on('$locationChangeStart', function (event, next, current) {

您好,当用户在地址栏中键入/定价时,我必须停止导航 并仅在激发$location.path(“/pricing”)时导航


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

您可以做的一件事是设置一个
标志
,并仅在标志为
true
时导航,否则禁止在
位置更改开始
中执行默认操作

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