Advanced Options in Meteor Router

I have a way to Meteor

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

      

I added a question mark to indicate that it is sometimes groupId

not used. In data

I check if the this.params.hasOwnProperty('groupId')

groupId is set using , but I ran into the fact that sometimes the router thinks the groupId is set even if it is not (not sure why) but the value undefined

.

So I tried

console.log(this.params.hasOwnProperty('groupId'));
console.log('groupId' in this.params);
console.log(this.params.groupId);

      

and they value the value

> true
> true
> undefined

      

So, I guess hasOwnProperty

not the best way to check if set groupId

as it does not check for undefined values.

What would be the best way to test this? Why hasOwnProperty

evaluates to true even though my url is /my-url

?

+3


source to share


1 answer


I think you have already answered your question. I have the same problem and my check:

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

      



It's not confirmed yet, but I think as long as you provide :groupId

, you already have it in the parameters, whether it exists or not.

+2


source







All Articles