2015-10-17 107 views
1

我有以下代码:流星的铁:路由器loadingTemplate不会呈现

Router.configure({ 
     layoutTemplate: 'commonTemplate', 
     loadingTemplate: 'loadingApp' 
    }); 

Router.route('/configuration', { 
    name:'configuration', 
    template:'configuration', 
    onBeforeAction: function(){ 
     this.layout(null); 
     if (Session.get('appReady')){ 
      this.next(); 
     } else { 
      console.log("loading app..."); 
      this.render('loadingApp'); 
     } 
    } 
}); 

加载应用程序...”正确的控制台中显示。 但是在那段时间(等待会话变量),不显示加载模板(既不来自Router.configure也不来自this.render)。 此外,当会话变量为true时,配置模板正确呈现。

这是一个铁:路由器错误或我做错了什么?

+0

是否使用的是流星铁路由器的版本? – Marztres

回答

1

您的代码正在为我工​​作,也许问题是您的加载模板未正确显示加载内容。我使用https://atmospherejs.com/sacha/spin包中的加载模板测试了代码,并且运行良好。

您可以从atmospherejs安装包sacha:spin并配置Iron Router以使用加载模板,该软件包易于使用,您必须在需要加载动画的位置使用模板“加载”。

1)meteor add sacha:spin

2)在你的路由器的文件:

Router.configure({ 
    loadingTemplate: 'loading' 
}); 

Router.route('/test', { 
    name: 'test', 
    template: 'test', 
    onBeforeAction : function() 
    { 
     this.layout(null); 
     if (Session.get('appReady')){ 
      this.next(); 
     } else { 
      console.log("loading app..."); 
      this.render('loading'); 
     } 
    } 
    } 
); 
相关问题