0

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?

4

1 回答 1

2

你试过用 替换notFound:notFoundTemplate?Iron Router 示例使用notFound但我只能notFoundTemplate在源代码中找到并且对我有用。

Router.map(function() { 
    this.route('story', {
        path: '/story/:_id',
        data: function() {
            return Stories.findOne({displayId: +this.params._id}); 
        },
        notFoundTemplate: 'storyNotFound'
    });
});
于 2013-08-19T19:54:10.647 回答