How do I do variable number of parameters in IronRouter?

I am fetching photo Albums from iOS. Photo albums have local identifiers, such as 11111111-1111-DDDD-FFFF-12334567890ABCDEH/L0/040

My app has URLs such as

/albums/11111111-1111-DDDD-FFFF-12334567890ABCDEH/L0/040

The extra slashes in the URL confuse Iron Router into thinking that there are three variable parameters, not one. Therefore, when I try to route it to

'/albums/:id', it complains.

I could do /albums/:id/:id2/:id3, but being new to iOS, I don’t know if all local Idendifiers have the same format and whether it’s future-proof (btw, does anyone know what /L0/040 means?)

So, what’s the generic way to accept one parameter with variable number of dashes in it?

Also, is it a good practice to do what I am doing?

Try looking in to using escape characters to generate the string you are going to use for your URL.

http://www.w3schools.com/js/js_strings.asp

Look at the examples about Special Characters.

/ encodes to %2F. In JavaScript, you can run encodeURIComponent('/') and it should return %2F. So pass your album ID with that instead of slashes.

let albumID = encodeURIComponent('11111111-1111-DDDD-FFFF-12334567890ABCDEH/L0/040')

Result: 11111111-1111-DDDD-FFFF-12334567890ABCDEH%2FL0%2F040

1 Like

I think this explanation should help you.
// given a url like "/post/5/comments/100"
Router.route(’/post/:_id/comments/:commentId, function () {
var id = this.params._id; // "5"
var commentId = this.params.commentId; // “100”
});

U can add multiple “/” with more than 1 defined variable on Meteor Side as well.

Source: http://iron-meteor.github.io/iron-router/

That only works if you know the number of variable parameters ahead of time, no?

BTW, found that when you do "Router.go(“path”) on iOS, and the path does not exist, Meteor seems to restart or something (Meteor.startup() hooks start executing)