流路由器布局的流星渲染两次 [英] meteor with flow router layout is rendered twice
问题描述
我不知道为什么,但是我的布局被渲染了两次.
I don't know why but my layout is rendered two times.
这是我的index.html:
Here is my index.html:
<head>
<title>title</title>
</head>
<body>
{{>layout}}
</body>
这是我的布局:
<template name="layout">
{{#if canShow}}
{{>Template.dynamic template=content}}
{{else}}
{{> loginButtons}}
{{/if}}
</template>
因此,这里没有路由,我的模板仅显示一次.
So here without route my template is display just one time.
这是我的路线:
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({});
}
});
推荐答案
您无需在主体中渲染布局.
you don't need to render layout in the body.
路由器将负责渲染.
所以,只需
<body>
</body>
或者根本不拥有它.
感谢Keith,我对我的问题有了更好的了解.这是他的评论:
Thanks to Keith, I have a better understanding of my problem. Here is his comment:
要记住的一件事是,您在流星中编写的所有html都不会保留为html.所有这些都转换为javascript.诸如index.html之类的东西不会被推送到browsersr.流星只是将您编写的所有html转换为javascript并根据您的代码所说的来呈现它所需的内容.这就是它知道如何动态更改和重新呈现html
对于诸如更改标题或添加meta之类的事情,我们可以直接在javascript中完成.
For things like changing title of the head or add meta etc, we can do it directely in the javascript.
例如:流星-设置文档标题
这篇关于流路由器布局的流星渲染两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!