meteor with flow router layout is rendered twice

余生颓废 提交于 2019-12-10 18:54:02

问题


I don't know why but my layout is rendered two times.

Here is my index.html:

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

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

Here is my layout:

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

So here without route my template is display just one time.

Here is my route:

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

But with this route my template is display a second time.

This is my helpers, I think there is nothing to do with this problem but we never know.

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


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


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

回答1:


you don't need to render layout in the body.

The router will take care of the rendering.

so, just have

<body>
</body>

or don't even have it at all.

Edit: Thanks to Keith, I have a better understanding of my problem. Here is his comment:

one thing to keep in mind, all the html you write in meteor isn't kept as html. It all gets converted to javascript. Things like index.html do not get pushed to the browsesr. Meteor just takes all the html you write converts it to javascript and renders what it needs to based on what your code says. This is how it knows todynamically change and rerender html

For things like changing title of the head or add meta etc, we can do it directely in the javascript.

ex: Meteor - Setting the document title



来源:https://stackoverflow.com/questions/33356401/meteor-with-flow-router-layout-is-rendered-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!