简体   繁体   中英

meteor iron router with data not rendering

I have a meteor project in which I'm trying to render a page with url data, however Meteor is not rendering the right template...

This is my iron router code:

Router.map(function() {
  this.route('profile', {
    path: '/profile/:_id',
    template: 'profile',
    data: function () {
      console.info(this);
      return Meteor.users.findOne({_id: this.params._id});
    }
  }),
  this.route('info'),
  this.route('home', {
    path:'/',
  }),
  ...

and the (simple) template:

<template name="profile">
    {{user}}
</template>

with this helper function:

Template.profile.helpers({
    user: function() { return this; }
)};

I know Meteor goes through the route since the console.info() in the router function dumps an object three(!) times in the console. However I only get to see my homepage and I never get to the profile page.

All information I could find about this came from iron router tutorials or the docs and shows (about) the exact code I have. Has anyone had this problem before? What am I doing wrong?


UPDATE:

I also noticed that when I add an action function to the route, this function never runs...

action : function () {
    console.info("action running!");
    if (this.ready()) {
        this.render();
    }
}

I think there is nothing you have presented here. You just need to publish data from users collection. more about publications

Ok seems I made a stupid mistake:

I blocked access to a profile unless it is your own profile. I was testing the access to my page with the wrong user _id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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