【问题标题】:Iron Router not working like expectedIron Router 无法按预期工作
【发布时间】:2014-12-08 14:42:54
【问题描述】:

我玩了一下 Iron Router (Tutorial),但我的模板不能正常工作。

html:

<head>
  <title>MY TITLE</title>
</head>

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

<template name="hello">
  This is the hello template.
</template>
<template name="home">
  This is the home template.
</template>

JS

Router.map(function(){
    this.route('hello');
    this.route('home', {path: '/'} );
});

当我启动流星时,它会正确呈现头部中的标题,但它没有显示正文部分中我的模板中的任何内容。 Meteor 没有抛出任何错误,但在浏览器控制台中我有 6 个错误:

[Error] TypeError: undefined is not a function (evaluating 'Template.__create__')
    (anonyme Funktion) (iron-dynamic-template.js, line 416)
    (anonyme Funktion) (iron-dynamic-template.js, line 433)
    global code (iron-dynamic-template.js, line 440)
[Error] TypeError: undefined is not an object (evaluating 'Parent.prototype')
    _inherits (meteor.js, line 220)
    (anonyme Funktion) (iron-layout.js, line 150)
    (anonyme Funktion) (iron-layout.js, line 487)
    global code (iron-layout.js, line 494)
[Error] TypeError: undefined is not a constructor (evaluating 'new Iron.Layout({template: this.options.layoutTemplate})')
    constructor (iron-router.js, line 1475)
    (anonyme Funktion) (iron-router.js, line 1771)
    (anonyme Funktion) (iron-router.js, line 1784)
    global code (iron-router.js, line 2356)
[Error] TypeError: undefined is not an object (evaluating 'Package['iron-router'].RouteController')
    global code (global-imports.js, line 3)
[Error] ReferenceError: Can't find variable: Template
    (anonyme Funktion) (template.bla.js, line 2)
    global code (template.bla.js, line 20)
[Error] ReferenceError: Can't find variable: Router
    (anonyme Funktion) (bla.js, line 1)
    global code (bla.js, line 6)

有人知道怎么回事吗?

【问题讨论】:

  • 您的错误主要是未定义的符号,您确定您正确添加了iron:router 包吗? meteor add iron:router
  • 我希望如此。我刚刚通过npm 安装了陨石。在新的流星项目中,我刚刚通过mrt add iron-router 安装了 Iron-router。安装日志告诉我一切都很好。
  • 你应该做的是:meteor add iron:router。从您的错误日志看来,您使用的是过时的版本。
  • 好的,下次我应该更好地阅读 cmets。现在可以了。谢谢大家!

标签: meteor iron-router


【解决方案1】:

如果你有同样的问题:

答案是不要通过陨石安装铁路由器。看起来 Iron-router 现在是一个智能包,您现在可以通过流星直接添加它。

正确 通过以下方式安装 Iron-router:

meteor add iron:router

错误(已弃用):

mrt add iron-router

【讨论】:

    【解决方案2】:

    也许先检查你的版本然后更新。您的错误来自图书馆。

    meteor remove iron:router
    meteor update
    meteor add iron:router
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      • 1970-01-01
      • 2022-01-21
      • 2013-12-23
      • 2014-12-09
      • 2016-01-13
      • 2020-09-21
      相关资源
      最近更新 更多