gpt4 book ai didi

javascript - 铁 :router not rendering template

转载 作者:行者123 更新时间:2023-11-29 10:38:38 25 4
gpt4 key购买 nike

我正在使用 iron:router 包开发 meteor 。我的 javascript 文件包含:

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

Router.route('/hello', function () {
this.render('hello');
});

我的 html 文件包含:

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

<body>
<h1>Welcome to Meteor!</h1>

</body>

<template name="hello">
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>

<template name="home">
<h2>Home</h2>
<p>You are on the home screen.</p>
</template>

无论我写什么(localhost:3000/hellolocalhost:3000/),如 the tutorial 中指定的那样,无论如何它根本不会呈现任何模板。它只是显示标题“Welcome to Meteor!”就是这样。

当我写入任何其他未声明的地址时,例如 localhost:3000/abc,它会显示:

Welcome to Meteor! Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/abc."

所以它肯定在 javascript 文件中做了一些正确的事情,因为它识别了它应该知道的模板,但是当写入正确的地址时,它仍然没有显示任何内容。

我尝试查看其他解决方案,检查包名称是“iron:router”而不是“iron-router”,以及其他解决方案,但没有任何效果。请帮助我...

编辑:根据要求,这里是项目的存储库 https://github.com/yokhen/test2

最佳答案

首先我必须添加 EJSON 包,因为 iron:router 没有看到它(虽然我在 Windows 上测试它,也许这就是我遇到这个问题的原因)

meteor add ejson 解决了

您的项目目录应如下所示:

enter image description here

路由.js

Router.route('/', function () {
this.render('Home');
});

Router.route('/items');

test2.js

Template.items.helpers({

});

Template.items.events({

});

Template.Home.helpers({

});

Template.Home.events({

});

test2.html

<template name="Home">
<h1>Simplest template home ever</h1>
</template>

<template name="items">
<h1>Simplest home items template</h1>
</template>

关于javascript - 铁 :router not rendering template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32799670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com