模板无法找到我的命名铁路由器路由

时间:2014-12-13 19:38:44

标签: meteor iron-router

在使用铁路由器的流星项目中,我的模板中的pathFor找不到命名路由。我想我已经遵守了guides

中的语法

这是空格键代码:

<a href="{{pathFor 'tag.show' _id=this._id }}" class="tag" id="{{title}}">{{title}}</a>

这是铁路由器代码:

Router.route('/tags/:_id', function() {
  this.layout('layout');

  this.render('tags');

  this.render('tagDetail', {
    to: 'topDrawer',
    data: function() {
      return Tags.findOne({
        _id: this.params._id
      });
    }
  });
}, {
  name: 'tag.show'
});

我做错了什么?

编辑:我的控制台中的确切错误是

pathFor couldn't find a route named "tag.show"

编辑2:对于踢,我尝试按名称检索另一条更简单的路线:

Router.route('/', function() {
  this.render('home');
}, {
  name: 'home'
});

Router.go('post.show');

我得到一个'未定义'的错误。我无法解决这个问题。

1 个答案:

答案 0 :(得分:0)

我认为你的声明倒退了,试试:

Router.route('tag.show', function() {
  this.layout('layout');

  this.render('tags');

  this.render('tagDetail', {
    to: 'topDrawer',
    data: function() {
      return Tags.findOne({
        _id: this.params._id
      });
    }
  });
}, {
  path: '/tags/:_id'
})

顺便说一下,这可能是由铁路由器api的变化引起的。我使用的版本是0.9.4,这就是我在该版本中声明路由的方式:

this.route('home', {path: '/'});

然后在其他地方我定义了一个自定义控制器:

HomeController = RouteController.extend({
  // nothing yet
});
相关问题