在使用iron-router的流星项目中,我的模板中的pathFor找不到命名路线。我想我已经遵守了语法guides https://github.com/EventedMind/iron-router/blob/devel/Guide.md#named-routes.
这是空格键代码:
<a href="{{pathFor 'tag.show' _id=this._id }}" class="tag" id="{{title}}">{{title}}</a>
这是iron-router代码:
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');
我收到“未定义”错误。我一直没能解决这个问题。
我认为你的声明倒退了,尝试:
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 路由器 api 的更改引起的。我使用的版本是 0.9.4,这就是我在该版本中声明路由的方式:
this.route('home', {path: '/'});
然后我在其他地方定义了一个自定义控制器:
HomeController = RouteController.extend({
// nothing yet
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)