Question

I would like my Meteor app to use IronRouter for client-side routing.

My routing code looks as follows:

Router.map(function() { 
    this.route('story', {
        path: '/story/:_id',
        data: function() {
            return Stories.findOne({displayId: +this.params._id}); 
        },
        notFound: 'storyNotFound'
    });
});

I have 2 templates corresponding to this route:

<template name="story">
    Welcome to story: {{this.displayId}}.
</template>

<template name="storyNotFound">
    Story not found
</template>

Problem: the 'storyNotFound' template is never rendered, not even when

Stories.findOne({displayId: +this.params._id}) 

returns undefined.

Instead, the 'story' template is rendered with the text "Welcome to story: ".

What am I missing?

Was it helpful?

Solution

Have you tried replacing notFound: with notFoundTemplate ? The Iron Router example uses notFound but I could only find notFoundTemplate in the source code and that worked for me.

Router.map(function() { 
    this.route('story', {
        path: '/story/:_id',
        data: function() {
            return Stories.findOne({displayId: +this.params._id}); 
        },
        notFoundTemplate: 'storyNotFound'
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top