【问题标题】:How to use one template in multiple Ironrouter route?如何在多个 Ironrouter 路由中使用一个模板?
【发布时间】:2017-07-30 00:10:32
【问题描述】:

我想用路由“/”和“/home”显示名为“home”的模板,但我的代码不起作用

/** Iron router config file **/
Router.configure({
  layoutTemplate: 'layout',
  notFoundTemplate: '404',
  loadingTemplate: 'loading',
  fastRender: true,
});

// Home
Router.route('/', {
  name: 'home',
  waitOn: function() {
    return [
      Meteor.subscribe('infosContainers'),
      Meteor.subscribe('infosMachines'),
      Meteor.subscribe('alertes'),
    ];
  },
  fastRender: true,
});

Router.route('/home', {
  name: 'home',
  waitOn: function() {
    return [
      Meteor.subscribe('infosContainers'),
      Meteor.subscribe('infosMachines'),
      Meteor.subscribe('alertes'),
    ];
  },
  fastRender: true,
});

它不喜欢模板“家”在 2 条路线中的事实(因为如果我在第二条路线中设置 name: sokasok 它可以工作)

你能帮我吗?

【问题讨论】:

    标签: templates meteor iron-router


    【解决方案1】:

    'name' 不是用于模板渲染的,它是路由的名称。您需要做的是在路由的action 中调用this.render('home')

    Router.route('/home', {
      waitOn: function() {
        return [
          Meteor.subscribe('infosContainers'),
          Meteor.subscribe('infosMachines'),
          Meteor.subscribe('alertes'),
        ];
      },
      action: function(){
          this.render('home');
      }
      fastRender: true,
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2016-04-10
      • 2013-10-23
      相关资源
      最近更新 更多