Search code examples
meteoriron-router

blog name in url instead of id in meteor


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

Solution

  • For this I end up creating a link using the blog name and id of the record(last 5 letters)

    Like

    post-name-xh45d