Skip to main content
 首页 » 编程设计

meteor中url中的博客名称而不是meteor中的id

2025年02月15日114lori

我有一个博客,我想要博客文章名称而不是博客 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 
     } 
 });