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?
any tips on what i’m missing?
none
April 9, 2015, 7:08am
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
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
1 Like
Thanks! That was what I was missing. Learning as I go
cstrat
April 9, 2015, 8:38am
7
Have a read of this:
http://themeteorchef.com/recipes/slugged-routes/
Steps you through how you can do this yourself.
1 Like