javascript - Optional parameters in Meteor router -


i have path in meteor

path: '/my-url/:groupid?', 

i have added question mark indicate groupid not used. in data check whether group id set this.params.hasownproperty('groupid') have come across router thinks groupid set if isn't (don't know why) value undefined.

therefore, tried

console.log(this.params.hasownproperty('groupid')); console.log('groupid' in this.params); console.log(this.params.groupid); 

and evaluate to

> true > true > undefined 

so guess hasownproperty not best way check whether groupid set since doesn't check undefined values.

what better way check this? why hasownproperty evaluate true if url /my-url?

i think you've answered on question. have same problem , check is:

if (this.params.groupid) { } else { } 

this not yet confirmed, think long provide :groupid, you're have in params, regardless exists or not.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -