Search code examples
meteoriron-router

Route data not accessible in template


I have a problem accessing the data from an route.

Router

Router.route('/view/:_id', {
    name: 'locationView',
    data: function() { return Locations.findOne(this.params._id); }
});

Locations is a MongoDB Collection that i've subscribed to. I can access it via a helper method on another template without problems. It has objects like name, address etc.

Template

<template name="locationView">
    <h1>{{name}}</h1>
</template>

Demo

Application hosted on meteor.com

On the front-page you can see that the entries from Locations are accessible from other templates over helper methods. So why i can't access them via the data object from the route?


Solution

The problem was adding the objects via mongo shell. That caused the ObjectID(xxx) stuff to appear in the _id of the object.

I've added some test objects via collection method 'insert' and everything works fine!


Solution

  • Solution

    The problem was adding the objects via mongo shell. That caused the ObjectID(xxx) stuff to appear in the _id of the object.

    I've added some test objects via collection method 'insert' and everything works fine!