Question: how do I use something besides /:_id for url?


#1

Beginner Question: So if I were making an app similar to microscope, but I wanted to use something besides :_id for the url path, how would I do that.

I currently have:

Router.route('/bands/:_id', {
    name: 'bandPage',
    data: function() {return Bands.findOne(this.params._id);}
});

but I would like to do something like

Router.route('/bands/:bandName', {
    name: 'bandPage',
    data: function() {return Bands.findOne(this.params.bandName);}
});

Is this possible?


#2

Short answer - yes (-:


#3

any tips on what i’m missing?


#4

Nothing special, but you have to control the uniqueness of this field
I’m using ongoworks:speakingurl for this purpose, but before adding to DB, I’m checking uniqueness


#5

This should work fine. You may be missing the field in the mongo query:

Router.route('/bands/:bandName', {
    name: 'bandPage',
    data: function() {return Bands.findOne({bandName: this.params.bandName});}
});

Useful package for auto generating unique slugs: todda00:friendly-slugs


#6

Thanks! That was what I was missing. Learning as I go :slight_smile:


#7

Have a read of this:

http://themeteorchef.com/recipes/slugged-routes/

Steps you through how you can do this yourself.