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?
2
Answers
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.
You can try slugify to push the
data.title
as a pretty url.