Hey guys,
I am using IronRouter and a route that renders one specific article.
The articlie is retrieved from the database via a unique string (a slug) which is part of the url.
I want to render a notFound template if the slug in the url is wrong (eg. does not exist).
code:
this.route('article', {
path: '/artikel/:slug',
template: 'article',
waitOn: function() {
return Meteor.subscribe('one-article', this.params.slug);
},
data: function() {
return Articles.findOne({slug: this.params.slug});
},
onAfterAction: function() {
if (!Meteor.isClient) {
return;
}
var article = Articles.findOne({slug: this.params.slug});
if (!article) {
this.render('notFound');
}
}
});
The problem with this code is that even if the slug is valid, the not found template flashes up for a few seconds before the article is rendered.
Has anyone had this problem before?
How did you solve it?