【问题标题】:Error when using iron:router with Meteor 0.9.3.1使用 Iron 时出错:路由器与 Meteor 0.9.3.1
【发布时间】:2014-12-02 01:56:54
【问题描述】:

我正在试验 Meteor 和 Iron:router。我 git 从https://github.com/EventedMind/iron-router.git 克隆了示例。然后我 cd-ed 进入 samples/basic,然后运行流星更新和流星。我的流星版本是0.9.3.1

当我导航到该网站时,控制台中显示一个错误并且页面为空。错误如下:

Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it?
at null._render (http://localhost:3000/packages/iron_dynamic-template.js?32038885cb1dad7957291ffebfffcb7f8cd57d20:239:17)
at doRender (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1853:25)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1795:16
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2029:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1794:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1793:19)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1847:10 debug.js:41

有人可以告诉我我做错了什么吗?

提前致谢。

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    您遇到此问题的原因是iron-router@1.0.0-pre-x(如 1.0 的 Beta)与当前使用的 0.9.x 版本的 Iron 路由器之间存在差异。

    为模板route 定义http://localhost:3000/route 路由的旧符号如下:

    Router.route("route", { path : '/' });
    

    但是在新版本中,目前在 github on devel 上(我假设示例基于如下):

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

    问题是使用底部的符号会导致错误Couldn't find a template named "/",因为Route.route 的第一个参数现在是路径而不是模板。

    解决这个问题的方法是使用 Iron Router 的预发布版本(版本字符串可以在 github 上的 package.js 文件中找到):

    meteor remove iron:router
    meteor add iron:router@1.0.0-pre3
    

    或者通过查看与 github 上的版本捆绑在一起的示例来使用旧的表示法,而不是像这样的 devel 分支:https://github.com/EventedMind/iron-router/tree/v0.9.2-rc0

    【讨论】:

    • 非常感谢 Akshat。当我降级到 Iron:router@1.0.0-pre3 时,它就像你提到的那样工作
    • 我现在也面临着另一个挑战。一旦我将模板和 Router.route 定义移动到子文件夹(例如“/client/core”)中,应用程序就无法正确路由了。
    • @3thanZ 这个路由器版本实际上仍在开发中。它需要在服务器端和客户端(根文件夹)设置路由,以使 404 正常工作。如果你想使用当前版本的 Iron 路由器,你需要 downgrade 到 0.9.3
    • 谢谢@Akshat,我在使用最新的 Iron:router 后使用了你上面提到的方法:Router.route("route", { path : '/' });跨度>
    猜你喜欢
    • 2016-06-03
    • 2015-08-22
    • 1970-01-01
    • 2013-08-14
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 2015-05-24
    相关资源
    最近更新 更多