0

我对 Meteor 和 Iron Router 还很陌生,我正在尝试创建一个看起来像这样的路线 '/users/hippomoe/bookmarks/Kj6ecNk7DeW7PmmGA' 其中 hippomoe 将是当前登录的用户,而 Kj6ecNk7DeW7PmmGA 将是一个书签。我尝试过的一些事情是添加一个把手助手来提供用户名

bookmark: function() {
    return {
        _id: this._id,
        user: Meteor.user().username
    };
}

我还尝试在 RouteController 定义的数据上下文中定义 user: Meteor.user().username 。在这两种情况下,我都会收到以下错误:“您调用 Route.prototype.resolve 时缺少参数。在参数中找不到“用户””

我尝试找到一个示例来说明这种类型的路线(我认为这很常见)。我在 StackOverflow 上看到的与此相关的其他问题是关于让用户与特定文档相关联,而不是与当前登录的用户相关联。

似乎我错过了一些简单的东西。有人可以提供/指向我如何实现这一目标的简单示例吗?

4

3 回答 3

1

I'm having difficulty understanding why you would need such a route. If you already know the name of the logged in user, why would you need to have it once more in the route? Or is this meant to be server-side? In that case, please show your routes.

Otherwise, does this not work:

Router.map(function () {
  this.route('postShow', {
    path: '/users/:ignoreme/bookmarks/_id',
    data: function () {
      var params = this.params;
      var user = Meteor.user().username;
      if (user == params.ignoreme) {
          ...
      } else {
          return "something went wrong";
      }
    }
  });
});

This is just to allow the url pattern you want, but again, I don't see why you wouldn't just use a URL /user/bookmarks or similar and then change the logic to depend on Meteor.user().

于 2013-12-12T23:40:48.910 回答
0

我在问题中写的车把助手

bookmark: function() {
    return {
        _id: this._id,
        user: Meteor.user().username
    };
}

如果我正确地指定了 pathFor 语法,就会起作用。我的 pathFor 应该是这样的

{{pathFor 'saveBookmark' bookmark}} 

我无意中忘记了书签!

于 2013-12-13T01:01:05.993 回答
0

我认为您在 _id 之前缺少一个“:”,试试这个:

path: '/users/:ignoreme/bookmarks/:_id',
于 2013-12-13T03:59:35.643 回答