Reputation: 3043
I've a blog and I want the blog post name instead of blog id in how to do this
I want the url like mysite.com/firs-post
not like mysite.com/_id
code
Router.map("blogpost",{
path:"/blog/:slug",
template:"singlepost",
data:function(){
return blog.findOne({});//want to return single blog
}
});
the blog post name may be duplicate,
I want to redirect to particular blog post without the id in url
Upvotes: 2
Views: 264
Reputation: 3043
For this I end up creating a link using the blog name and id of the record(last 5 letters)
Like
post-name-xh45d
Upvotes: 1
Reputation: 973
One idea could be to have a link on the template like for example:
<a href="/blog_post_name"></a>
Now in iron:router
Router.map("blogpost",{
path:"/blog/:slug",
template:"singlepost",
waitOn: function () {
return [Meteor.subscribe('blog')];
},
data: function(){
return blog.findOne({name: this.params.slug});//want to return single blog
}
});
Upvotes: 1