重定向在本地通知点击离子不工作

Redirect on local notification click in ionic not working

本文关键字:工作 通知 重定向      更新时间:2023-09-26

所以我有本地通知设置使用ngcordova本地通知插件。它们正在发射并被应用程序接收。然而,在那之后,我似乎无法重定向到我想要的特定页面。以下是我的相关代码,点击事件内部的控制台日志正在触发,并且注释掉的代码将重定向到页面,但它在ionic之外(css不加载,js不引导等)

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova', 'ionic-numberpicker', 'ngStorage'])
.config(function($ionicConfigProvider){
    $ionicConfigProvider.views.maxCache(0);
  })
.run(function($ionicPlatform, $rootScope, $cordovaLocalNotification) {
  $ionicPlatform.ready(function() {
    $rootScope.$on("$cordovaLocalNotification:click", function(notification, $state) {
      console.log('clicked notification');
      //window.location.href = 'templates/notification.html';
      $state.go('notification');
    });
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
  });
})
.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('app', {
    url: '/app',
    abstract: true,
    cache:false,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })
  .state('app.settings', {
    url: '/settings',
    cache:false,
    views: {
      'menuContent': {
        templateUrl: 'templates/settings.html',
        controller: 'SettingsCtrl'
      }
    }
  })
  .state('app.list', {
      url: '/list',
      cache:false,
    views: {
        'menuContent': {
          templateUrl: 'templates/list.html',
          controller: 'ListCtrl'
        }
      }
    })
    .state('app.home', {
      url: '/home',
      cache:false,
      views: {
        'menuContent': {
          templateUrl: 'templates/home.html',
          controller: 'HomeCtrl'
        }
      }
    })
    .state('app.contact', {
      url: '/contact',
      cache:false,
      views: {
        'menuContent': {
          templateUrl: 'templates/contact.html',
          controller: 'ContactCtrl'
        }
      }
    })
  .state('app.user', {
    url: '/users/:userId',
    cache:false,
    views: {
      'menuContent': {
        templateUrl: 'templates/users.html',
        controller: 'UsersCtrl'
      }
    }
  })
    .state('notification', {
      url: '/notification',
      cache:false,
      templateUrl: 'templates/notification.html',
      controller: 'NotificationCtrl'
    });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/home');
});

$state.go('notification')如果你在.run函数中导入状态,而不是在click函数中导入状态,那么它实际上是有效的。