使用查询字符串的参数调用`$ state.go(' tab.events')`

时间:2018-02-03 07:16:48

标签: angularjs ionic-framework angular-ui-router

离子V1项目的app.js中已有设置。点击某些按钮会为:period分配不同的值('今天','明天','周末'等)。

  .state('tab.events', {
    url: '/events/:categoryTitle?p=:period',
    views: {
      'tab-events': {
        templateUrl: 'templates/tab-events.html',
        controller: 'EventsCtrl'
      }
    }
  })

以下代码用于在登录后重定向到http://localhost:8100/#/tab/events/

$scope.signWithFackBook = function () {
  facebookConnectPlugin.login(["public_profile"], function (data) {
    console.log("Info:" + JSON.stringify(data));
    facebookConnectPlugin.getAccessToken(function (token) {
      console.log("Token: " + token);
      $ionicViewService.nextViewOptions({ disableBack: true });
      localStorage.setItem('token', token);
      $state.go('tab.events'); // Need to go to http://localhost:8100/#/tab/events/?p=today instead
    });
  }, function (error) {
    console.log("Error:" + JSON.stringify(error));
  });
};

但是,我希望将其重定向到http://localhost:8100/#/tab/events/?p=today。怎么做?

1 个答案:

答案 0 :(得分:2)

You are not sending the params in your $state request.

You have 2 params - categoryTitle - period

This is how you do it.

.state('tab.events', {
    url: '/events/:categoryTitle?p=:period',
    views: {
      'tab-events': {
        templateUrl: 'templates/tab-events.html',
        controller: 'EventsCtrl'
      }
    }
  });

$state.go('tab.events', {
   categoryTitle: null,
   period: 'today'
});