简体   繁体   English

铁路由器不会在Meteor中呈现模板

[英]iron-router does not render template in Meteor

I have installed the atmosphere package iron:router for my meteor application. 我已经为流星应用程序安装了大气包iron:router。 I am trying to add a simple route like this: 我正在尝试添加一条简单的路线,如下所示:

Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'notFound'
});

Router.route('/', {
    name : 'homeIndex'
});

I defined a template: 我定义了一个模板:

<template name="homeIndex">
    <h1>Test for my meteor application</h1>
</template>

And I add a yield - field to my layoutTemplate: 然后将yield-字段添加到我的layoutTemplate中:

<template name="layout">
    <div class="container">
        {{> yield}}
    </div>
</template>

But still when I go to '/' , I don't see anything of my template. 但是当我转到'/' ,仍然看不到模板的任何内容。

Also when I'm trying to add another route with another template, it doesn't work. 另外,当我尝试使用其他模板添加其他路线时,它不起作用。 I have installed the package through this command: meteor add iron:router 我已经通过以下命令安装了软件包: meteor add iron:router

Can someone please tell me what I'm doing wrong? 有人可以告诉我我在做什么错吗?

If you want to render a template when a user goes to a particular route, you should use this.render('templateName'); 如果要在用户转到特定路线时呈现模板,则应使用this.render('templateName'); . In your case, you only defined a named route , but you didn't specify which template to render. 在您的情况下,您仅定义了一个命名的route ,但没有指定要呈现的模板。

Router.route('/', function () {
    this.render('homeIndex');
}, {
    name: 'homeIndex'
});

When I looked at my console in the browser, I saw the iron router package was throwing an exception that EJSON was undefined in the javascript of the package. 当我在浏览器中查看控制台时,我看到铁路由器程序包引发了一个异常,即该程序包的javascript中未定义EJSON。 I installed the EJSON package with the command meteor add ejson , and it was fixed! 我用meteor add ejson命令安装了EJSON包,它是固定的! But thanks anyway for the help! 但是无论如何,谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM