0

我是 Ionic 和 AngularJS 的新手,不知道为什么这不起作用,我只想检查用户是否已经输入了卡号,如果没有,将他重定向到适当的页面这是我的控制器:

.controller('HomeCtrl', function($scope, $state) {
    if (localStorage.getItem("cardId") == "")
      {
        console.log("redirecting to login");
        $state.go('tab.dash');
      }
})

$state.go 似乎什么都不做,但控制台日志正确显示。我尝试使用 $timeout 和 $location.path 没有成功。

这是我的路线:

  $stateProvider

    .state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/tabs.html'
  })

    .state('tab.home', {
    url: '/home',
    views: {
      'tab-home': {
        templateUrl: 'templates/tab-home.html',
        controller: 'HomeCtrl',
      }
    }
  })

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl',
      }
    }
  })

  .state('tab.map', {
      url: '/map',
      views: {
        'tab-map': {
          templateUrl: 'templates/tab-map.html',
          controller: 'MapCtrl'
        }
      }
    })

  .state('tab.account', {
    url: '/account',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  });

      $urlRouterProvider.otherwise('/tab/home');
});

我做错了什么?我只是想改变状态...

谢谢 :)

4

0 回答 0