gpt4 book ai didi

javascript - 如何使用 Meteor Iron Router 创建单独的 HTML 模板文件

转载 作者:行者123 更新时间:2023-11-28 06:51:04 25 4
gpt4 key购买 nike

我有三个文件夹

client

router

server

client文件夹中,还有一个名为views的文件夹,其中包含名为layout.htmlhome.html<的文件/strong> 和 login.html

router文件夹中,有一个router.js文件,其中包含

Router.configure({
layoutTemplate: "Layout"
});

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

Router.route( "/login", function(){
this.render( "Login" );
});

在我的layout.html文件中

<template name="Layout">
<h1>Hello Layout</h1>
{{ > yield }}
</template>

hello Layout renders just fine, but the home template is not found.

如果我在 layout.html 中包含所有模板,则路由可以工作 4.0。

如何正确管理路由,以便每个模板都可以保留在自己的文件中?

更新这是其他各自的模板

<template name="Home">
<h1>This Is Home</h1>
</template>

and

<template name="Login">
<h1>This Is Login</h1>
</template>

更新2

我还尝试使用meteor-angular,它希望html文件名为name.ng.html。

从文件名中删除ng,使其与我上面描述的内容匹配,然后一切再次正常。我会把它留在这里,以防其他人遇到这个问题。

最佳答案

几天前我遇到了类似的问题。

如果您使用 Meteor 1.2 版,可能由于以下问题而无法工作:

https://github.com/iron-meteor/iron-middleware-stack/pull/7

您可以通过检查是否遇到如下异常来确认:

Exception in callback of async function: ReferenceError: EJSON is not defined

因此,虽然他们没有更新包来修复它,但添加“ejson”包:

meteor add ejson

之后,它应该可以工作。

关于javascript - 如何使用 Meteor Iron Router 创建单独的 HTML 模板文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957942/

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