如何使用yield和Iron-router?

如何使用yield和Iron-router?

问题描述:

所以我正在尝试做一个基本的流星应用程序..这里有三个文件。

So I am trying to do a basic meteor app at the moment.. here are the three files.

router.js:

router.js:

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

Router.route("/", {
    name : "homeIndex",
    data : function() {
        return {
            message : "Welcome to the Rocket Shop"
        }
    }
});

index.html:

index.html:

<template name="homeIndex">
    <h1>{{message}}</h1>
</template>

layout.html:

layout.html:

<template name="layout">
        {{> nav}}
        <div class="container">
            {{>yield}}
        </div><!-- /.container -->
</template>

当我在启动应用程序后转到localhost:3000时,我在浏览器控制台中获得了一个很长的堆栈跟踪页面正文不会加载。

When I go to localhost:3000 after starting the app I get a long stacktrace in my browser console and the body of the page does not load up.

22:35:57.444 Exception in callback of async function: MiddlewareStack.prototype.concat@http://localhost:3000/packages/iron_middleware-stack.js?ff70621b6c5f6a406edc60600c4b76126dae21d6:303:7
RouteController.prototype._runRoute@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:542:11
Route.prototype.dispatch@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:856:10
Route/route@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:713:5
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?ff70621b6c5f6a406edc60600c4b76126dae21d6:425:16
Meteor.bindEnvironment/<@http://localhost:3000/packages/meteor.js?5deab0885176b44ccbbbf0b5101b065971c8f283:999:17
dispatch@http://localhost:3000/packages/iron_middleware-stack.js?ff70621b6c5f6a406edc60600c4b76126dae21d6:449:3
RouteController.prototype.dispatch/</<@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:393:7
Tracker.Computation.prototype._compute@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:349:5
Tracker.Computation@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:237:5
Tracker.autorun@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:588:11
RouteController.prototype.dispatch/<@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:391:5
Tracker.nonreactive@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:615:12
RouteController.prototype.dispatch@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:390:3
Router.prototype.dispatch@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:1700:3
onLocationChange@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:1784:20
Tracker.Computation.prototype._compute@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:349:5
Tracker.Computation@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:237:5
Tracker.autorun@http://localhost:3000/packages/tracker.js?9309a5697855cef52b32921fbc9dcb1017c58b39:588:11
Router.prototype.start@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:1777:31
Router/</<@http://localhost:3000/packages/iron_router.js?dd5fa02859b6335661b94134bd9903be8eecf44d:980:9
.withValue@http://localhost:3000/packages/meteor.js?5deab0885176b44ccbbbf0b5101b065971c8f283:971:17
withoutInvocation/<@http://localhost:3000/packages/meteor.js?5deab0885176b44ccbbbf0b5101b065971c8f283:428:26
Meteor.bindEnvironment/<@http://localhost:3000/packages/meteor.js?5deab0885176b44ccbbbf0b5101b065971c8f283:999:17
onGlobalMessage@http://localhost:3000/packages/meteor.js?5deab0885176b44ccbbbf0b5101b065971c8f283:365:11
1 meteor.js:880:11

有谁可能知道我做错了什么?我只是按照复数教学并遵循所有指示。

Does anyone possibly know what I am doing wrong? I am just following a pluralsight tutorial and have followed all of the directions.

我找到了自己问题的答案在其他铁路由器问题上搜索* ..我不知道为什么它工作,但它解决了这个问题。我所要做的只是运行:

I figured out the answer to my own question after searching around * at other iron-router questions.. I have no idea why it worked, but it solved the issue. All I had to do was run:

meteor add ejson

我不再收到错误。

这是回答我问题的问题(在我的问题之后发布):
铁:路由器1.0.9不工作

Here is the question that answered my question (which was posted AFTER my question): Iron:router 1.0.9 Not working