Router.go不会在Template.events中重定向

时间:2017-09-11 10:58:11

标签: meteor iron-router

Routes.js:

Router.configure({
  layoutTemplate: "defaultLayout",
  before: function () {
    if(!Meteor.user()) {
      this.layout("loginLayout");
      this.render('login');
    }else{
      this.layout("defaultLayout");
      this.next();
    }
  }
});

Router.route('/',function(){
  this.render('login');
  this.layout('loginLayout');
});

Router.route('/botlist',{
  template: "projects",
  name: "projects",
  data: function(){
    return Projects.find({});
  },    
  waitOn: function(){
    return Meteor.subscribe('projects',Session.get("username"));
  }
});

我有一个js看起来像的登录页面:

....
  'click #btn-login'(e, t) {
    var username = $('#email').val(),password = $('#password').val();
    Meteor.call('loginWithad',username,password,function(err,response){
      if(response.err){
        ..              }
      else{
        Meteor.call('finishLogin',username,password,function(err,res){
          if(err){
            ...
          }
          else{
            Session.set("username",res.givenName);
            Router.go("/botlist"); //--> this router.go doesn't route to /botlist template                           
          }
        })
      ....

我的路由器定义有什么问题吗?我尝试了多种解决方案:

  1. this.redirect()
  2. Router.push
  3. this.stop()然后Router.go()

1 个答案:

答案 0 :(得分:0)

您需要提供路线名称作为参数。所以:

变化

Router.go("/botlist");

Router.go("projects");