Initially, I do not use Meteor by itself but Angular-Meteor. The underlying principles are still the same. My challenge involves validating a resource in a helper
function to determine its validity and make decisions based on the outcome.
I assumed that the find
and findOne
collection functions worked synchronously on the client side, but it appears that either they are not or I am implementing them incorrectly.
This is the code snippet I have:
this.helpers({
post() {
let _post = Posts.findOne({
_id: this.postId
});
if( typeof _post == 'undefined' )
return this.$state.go('404');
return _post;
}
});
The value of this.postId
is obtained from the URL parameters. While navigating within the application, everything works as expected. However, when I refresh the page, even though this.postId
is defined, Posts.find()
returns undefined
, resulting in a redirection to the 404 page.
How can I address this issue effectively?