【问题标题】:Meteor: IronRouter does not trigger notFound ruleMeteor:IronRouter 不会触发 notFound 规则
【发布时间】:2013-08-21 15:52:05
【问题描述】:

我希望我的 Meteor 应用程序使用 IronRouter 进行客户端路由。

我的路由代码如下:

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

我有2个模板对应这条路线:

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

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

问题:“storyNotFound”模板从不渲染,即使在

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

返回未定义。

相反,“故事”模板使用文本“欢迎来到故事:”呈现。

我错过了什么?

【问题讨论】:

    标签: javascript meteor iron-router


    【解决方案1】:

    您是否尝试将 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'
        });
    });
    

    【讨论】:

    • 您好,很抱歉给您带来了困惑。我在开发分支中清理了很多。通常,适用于模板的任何内容在选项末尾都有“模板”。 notFoundTemplate、layoutTemplate、yieldTemplates、模板。
    猜你喜欢
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    相关资源
    最近更新 更多