Meteor的铁:路由器loadingTemplate没有渲染

时间:2015-10-17 14:54:55

标签: meteor iron-router

我有以下代码:

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时,配置模板将正确呈现。

这是 iron:router 错误还是我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的代码对我有用,可能问题是您的加载模板没有正确显示加载内容。我使用https://atmospherejs.com/sacha/spin包中的加载模板测试了代码并且工作正常。

你可以从atmospherejs安装包sacha:spin并配置Iron Router使用加载模板,这个包很容易使用,你必须使用模板' loading'你想要加载动画的地方。

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');
        }
    }
  }
);
相关问题