我有一个博客,我想要博客文章名称而不是博客 ID 来了解如何执行此操作
我想要像 mysite.com/firs-post
这样的网址,而不是像 mysite.com/_id
代码
Router.map("blogpost",{
path:"/blog/:slug",
template:"singlepost",
data:function(){
return blog.findOne({});//want to return single blog
}
});
博客文章名称可能重复,
I want to redirect to particular blog post without the id in url
最佳答案
一个想法可能是在模板上添加一个链接,例如:
<a href="/blog_post_name"></a>
现在是铁:路由器
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
}
});
关于meteor - url中的博客名称而不是meteor中的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26889637/