Iron Router works with Meteor 3!

Hi,

I’m experiencing an issue where this.data in my template’s onCreated callback is wrapped in an extra value object, which shouldn’t be the case.

Here’s my router setup:

javascript

Router.route('/myRoute', {
  name: 'myRoute',
  data() {
    return MyCollection.findOne();
  },
});

And in my template:

javascript

Template.myRoute.onCreated(function () {
    console.log(this.data);
    // Currently shows: {value: myData}
    // Expected: myData (the actual document from MyCollection)
});

Expected behavior: this.data should directly contain the document returned by MyCollection.findOne().

Actual behavior: this.data contains {value: myData} where myData is wrapped inside a value property.

Has anyone encountered this issue? What could be causing this extra object wrapper, and how can I get the direct data without the value wrapper?

Thanks

Aletapia

There is no need to use async calls on the client side. Typically, your iron router usage is on the client side, so keep using as you would normally do.

Polygonwood

Dayd

I believe the normal pattern is to pass the data in the rendering call :

Router.route('/post/:_id', function () {
  this.render('Post', {
    data: function () {
      return Posts.findOne({_id: this.params._id});
    }
  });
});

Check the Iron Router manual for more examples.

I’ve always used the second way to declare a route, see the “Route Specific Options” section, but I’ll give the other method a try. Thanks!

https://iron-meteor.github.io/iron-router/#route-specific-options

But I would prefer to use the object version :slightly_smiling_face: