2013-08-19 29 views
0

我希望我的流星應用使用IronRouter進行客戶端路由。流星: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}) 

返回未定義。

取而代之的是,「故事」模板以文字「歡迎來到故事:」呈現。

我錯過了什麼?

回答

2

您是否試過用notFoundTemplate替換notFound:? Iron Router示例使用notFound,但我只能在源代碼中找到notFoundTemplate並且適用於我。

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

謝謝,源代碼在文檔:) –

+0

嘿,遺憾的混亂。我在開發部門清理了很多。通常,適用於模板的任何內容都在選項末尾有「模板」。 notFoundTemplate,layoutTemplate,yieldTemplates,模板。 – cmather