数据未渲染的陨铁路由器

meteor iron router with data not rendering

本文关键字:路由器 数据      更新时间:2023-09-26

我有一个流星项目,我试图渲染一个带有 url 数据的页面,但是 Meteor 没有渲染正确的模板......

这是我的铁路由器代码:

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:'/',
  }),
  ...

和(简单)模板:

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

使用此帮助程序函数:

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

我知道 Meteor 会通过这条路线,因为路由器函数中的 console.info() 在控制台中转储对象三次(!)。但是,我只能看到我的主页,而永远不会进入个人资料页面。

能找到的有关此的所有信息都来自铁路由器教程或文档,并显示了(关于)我拥有的确切代码。以前有人遇到过这个问题吗?我做错了什么?


更新:

我还注意到,当我向路由添加操作函数时,该函数永远不会运行......

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

我认为您在这里没有介绍任何内容。您只需要从用户集合发布数据。有关出版物的更多信息

好吧,

我似乎犯了一个愚蠢的错误:

我阻止了对个人资料的访问,除非它是您自己的个人资料。我正在使用错误的用户_id测试对我的页面的访问。