繁体   English   中英

Metoer.js:铁路由器Router.route()不起作用

[英]Metoer.js: iron-router Router.route() not working

我第一次使用Meteor.js和iron-router,到目前为止,除了iron-router之外,其他一切都进行得很好。 我在js文件的开头调用此代码。

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

真的很简单,这里没有发生任何有趣的事情,问题在于它根本不起作用。 如果导航到URL http://foobar.bar/find_tutors,则会收到此错误

Exception in defer callback: Error: Oh no! No route found for path: "/find_tutors"
at Utils.extend.onRouteNotFound (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1714:13)
at IronRouter.dispatch (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1201:19)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1666:12
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 Utils.extend.start (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1663:10)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1458:16
at _.extend.withValue (http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:891:17)
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:430:45 

我觉得有些不对劲,但是说实话,这段代码是如此简单,我不明白为什么我无法使它正常工作。 我说它应该到达该路线时才应该渲染该模板,这是错误的吗? 尽管我猜想它在route()功能块中的功能无关紧要,因为铁路由器甚至从未到达那里。

这是我可以提供的重新生成错误的最小代码集(尽管无论代码大小如何,都会发生错误。)

//test.js
Router.route('/find_tutors', function () {
  this.render('page');
});
if (Meteor.isClient) {
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

<!--- test.html --->
<head>
  <title>Test</title>
</head>

<body>
</body>

<template name="page">
  <h1>Welp.</h1>
</template>

此示例托管在cvoege.meteor.com上

我是白痴还是正在发生深深的事情?

iron:router在1.0.0版本中更改了某些api(目前仍在1.0.0-pre4中)。

似乎您以1.0.0的方式使用iron:router,而不是当前的(0.9.4)方式。

您可以通过以下方式将iron:router更新为1.0.0-pre4:

meteor update iron:router@1.0.0-pre4

更新

看来我滥用了更新功能。 请删除然后重新安装。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM