user1032369
user1032369

Reputation: 589

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

I'm using Meteor.js and iron-router for the first time, and so far everything is going well, except for iron-router. I call this code at the beginning of my js file.

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

Really simple, nothing interesting whatsoever going on here, the problem is it just doesn't work. I get this error if I navigate to the 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 

I feel like something obvious is off but honestly this code is just so simple I don't see why I can't get it to work. Am I wrong in saying that it should just render that template if it reaches that route? Though I suppose it doesn't even matter whats in the route() function block, because iron router never even gets there.

Here is the smallest set of code I can give to recreate the error (though the error happens regardless of the size of the code.)

//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>

This example is hosted at cvoege.meteor.com

Am I an idiot or is there something deep going on?

Upvotes: 2

Views: 712

Answers (1)

waitingkuo
waitingkuo

Reputation: 93754

iron:router changed some of its api in 1.0.0 version (still in 1.0.0-pre4 at this moment).

And it seems that you are using iron:router in the 1.0.0 way but not the current (0.9.4) one.

You can update your iron:router to 1.0.0-pre4 by

meteor update iron:[email protected]

Update

It seems that I misuse the update function. Please remove and then re-install it instead.

meteor remove iron:router
meteor add iron:[email protected]

Upvotes: 4

Related Questions