【问题标题】:meteor with flow router layout is rendered twice流路由器布局的流星被渲染两次
【发布时间】:2016-01-26 04:20:53
【问题描述】:

我不知道为什么,但是我的布局被渲染了两次。

这是我的 index.html:

<head>
  <title>title</title>
</head>

<body>
  {{>layout}}
</body>

这是我的布局:

<template name="layout">
  {{#if canShow}}
    {{>Template.dynamic template=content}}
  {{else}}
    {{> loginButtons}}
  {{/if}}
</template>

所以这里没有路由我的模板只显示一次。

这是我的路线:

FlowRouter.route('/', {
  action() {
    BlazeLayout.render("layout", {
      content: "home"
    });
  }
});

但是通过这条路线,我的模板会再次显示。

这是我的帮手,我认为与这个问题无关,但我们永远不知道。

Template.home.onCreated(function() {
  this.autorun(() => {
    this.subscribe('post');
  });
});


Template.layout.helpers({
  canShow() {
    return !!Meteor.user();
  }
});


Template.home.helpers({
  cats() {
    return Posts.find({});
  }
});

【问题讨论】:

    标签: layout meteor routing routes flow-router


    【解决方案1】:

    您不需要在正文中呈现布局。

    路由器会负责渲染。

    所以,只要有

    <body>
    </body>
    

    或者根本没有。

    编辑:感谢 Keith,我对自己的问题有了更好的理解。这是他的评论:

    要记住的一点是,您在流星中编写的所有 html 都不会保存为 html。这一切都被转换为javascript。 index.html 之类的东西不会被推送到浏览器。 Meteor 只需将您编写的所有 html 转换为 javascript 并根据您的代码内容呈现它需要的内容。这就是它知道动态更改和重新渲染 html 的方式

    更改头部标题或添加元数据等,我们可以直接在 javascript 中完成。

    例如:Meteor - Setting the document title

    【讨论】:

      猜你喜欢
      • 2018-03-21
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多