Exception in template helper: TypeError: Cannot read property '_id'

I have just moved from Flow router to Iron router and I now get this error:

Exception in template helper: TypeError: Cannot read property ‘_id’ of undefined at Object.tasks

I have changed this:
FROM: var appId = FlowRouter.getParam(“Id”);
TO: appId = this.params._id;

And when I click on the category links, content dont change.

When I navigate to a subpage like /network and then click a category link, then the content change but still no task list

you need to provide more code for this. In particular, we need know what this is in your code.

Router.route(’/tasks/:_id’, function () {
appId = this.params._id;

NAVI: template category:
a class=“nodec” href="/tasks/{{_id}}">input class=“mdl-navigation__link” id=“mainlink” style=‘width:100% border:0px;’ type=“text” value="{{categori}}" name=“catItem”>a

This seems not the whole code. But that’s my guess:

  • you called this.params._id; in a template-helper, not in the router-function as you showed in your code example.
  • FlowRouter.getParam("Id"); works everywhere and in particular in a template-helper, while this.params._id; can’t work in a helper, because this has a different meaning there.
  • If you need the appId in the “tasktemplate”, you should pass it as a param to this.render

See https://github.com/iron-meteor/iron-router#quick-start

Pro tip: Wrap your code-examples in three backticks `, so that it is easier to read.

1 Like

thanks, it works perfect…