The template cannot find my named iron router route
In a meteor project using iron-router, the pathFor in my template cannot find the named route. I think I stuck with the syntax in the manual .
Here's the code for the spatial symbols:
<a href="{{pathFor 'tag.show' _id=this._id }}" class="tag" id="{{title}}">{{title}}</a>
And here is the hardware router code:
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'
});
What am I doing wrong?
EDIT: Exact error in my console
pathFor couldn't find a route named "tag.show"
EDIT 2: For bumps, I tried to get another simpler route called:
Router.route('/', function() {
this.render('home');
}, {
name: 'home'
});
Router.go('post.show');
And I am getting "undefined" error. I have not been able to resolve this issue.
+3
source to share
1 answer
I think you have the declaration back, 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'
})
By the way, it might be caused by changing the iron router api. The version I'm using is 0.9.4 and this is how I declare routes in this version:
this.route('home', {path: '/'});
Then, elsewhere, I define a custom controller:
HomeController = RouteController.extend({ // nothing yet });
0
source to share