模板找不到我的命名铁路线 [英] Template can't find my named iron-router route

查看:43
本文介绍了模板找不到我的命名铁路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用iron-router的流星项目中,模板中的pathFor找不到命名的路线.我认为我遵守了指南.

In a meteor project using iron-router, a pathFor in my template can't find a named route. I think I've adhered to the syntax in the 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'
});

我在做什么错了?

我的控制台中的确切错误是

The exact error in my console is

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

对于踢球,我尝试通过名称检索另一条更简单的路线:

EDIT 2: For kicks, I tried retrieving another simpler route by name:

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

Router.go('post.show');

然后出现未定义"错误.我一直无法解决这个问题.

And I get an 'undefined' error. I haven't been able to solve this problem.

推荐答案

我认为您的声明向后,请尝试:

I think you have your declaration backwards, try:

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'
})

顺便说一句,这可能是由Iron router api的更改引起的.我使用的版本是0.9.4,这就是我在该版本中声明路由的方式:

By the way this may be caused by a change in the iron router api. The version I'm using is 0.9.4 and this is how I declare routes in that version:

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

然后在其他地方定义自定义控制器:

Then elsewhere I define a custom controller:

HomeController = RouteController.extend({
  // nothing yet
});

这篇关于模板找不到我的命名铁路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆