I have a path in Meteor
path: '/my-url/:groupId?',
I have added the question mark to indicate that sometimes groupId is not used. In data I check whether the group id is set with this.params.hasOwnProperty('groupId') but I have come across that sometimes the router thinks groupId is set even if it isn't (don't know why) but the value is undefined.
Therefore, I tried
console.log(this.params.hasOwnProperty('groupId'));
console.log('groupId' in this.params);
console.log(this.params.groupId);
and they evaluate to
> true
> true
> undefined
So I guess hasOwnProperty is not the best way to check whether groupId is set since it doesn't check for undefined values.
What will be a better way to check this? Why does hasOwnProperty evaluate to true even if my url is /my-url?
I think you've already answered yourself on your question. I have same problem and my check is:
if (this.params.groupId) {
} else {
}
This is not yet confirmed, but I think as long as you provide :groupId, you're already have that in params, regardless it exists or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With