功能后无法重定向到控制器

时间:2016-08-03 22:32:12

标签: javascript ember.js

我的application.js路由中有一个使用Github登录的操作,然后重定向到名为auth的控制器,如下所示:

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {
  actions: {
    login() {
      var controller = this.controllerFor('auth');
       this.get('torii').open('github-oauth2').then(function(authData){
         console.log(authData);
         controller.transitionTo('auth');
       }, function(error){
         console.log(error);
       });
    }
  }
});

但是我收到以下错误

ember.debug.js:19750 TypeError: controller.transitionTo is not a function
at application.js:8
at tryCatch (ember.debug.js:52155)
at invokeCallback (ember.debug.js:52170)
at publish (ember.debug.js:52138)
at ember.debug.js:41257
at invoke (ember.debug.js:990)
at Object.flush (ember.debug.js:1054)
at Object.flush (ember.debug.js:862)
at Object.end (ember.debug.js:176)
at Object.run (ember.debug.js:298)

我真的不知道我在这里失踪了什么。 我已经尝试了var controller = this.controller并且没有效果

1 个答案:

答案 0 :(得分:3)

Controller有transitionToRoute方法:

controller.transitionToRoute('auth');