Reputation: 755
I'm working on a Meteor app which uses ms-seo package. I was wondering if there is a way to make URLs more SEO friendly?
Router.route('/item/:_id', {
name: 'item.detail',
controller: 'ItemsController',
action: 'detail',
where: 'client',
onAfterAction: function() {
var data = this.data();
if (data) {
SEO.set({
title: data.title + ' - ' + data.company + ' (' + data.city + ')',
meta: {
'description': data.descriptionHTML
}
});
}
});
While this works perfect, the URL it produces is /item/5RTxofPPn3LwifP24
, I would like to push data.title
up in the url, so I can get /item/i-am-a-lower-case-dash-replaced-unique-title/
Are there packages for that?
Upvotes: 2
Views: 489
Reputation: 4376
You can try slugify to push the data.title
as a pretty url.
Upvotes: 0
Reputation: 4113
You need to create a slug. So your collection will have fields like:
Then to make your slug you can use something like https://atmospherejs.com/yasaricli/slugify to convert your title into a slug. Basically what it does is convert a title called "Unique Shopping Cart Item" to "unique-shopping-cart-item."
Then in your router you pass the slug in as your parameter.
Router.route('/blog/:slug',{
name:'blogPosts',
waitOn: function() { return Meteor.subscribe('collection'); },
data: function(){
var slug = this.params.slug;
return Collection.findOne({slug:slug});
// this is saying search the collection's slug for the passed in parameter which we're also calling "slug"
}
});
Upvotes: 5