2014-10-03 272 views
0

我正在使用流星與鐵:路由器包。我想只呈現一個基本的模板到一個佈局模板,但繼續接收錯誤:流星無法渲染動態模板

Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it? 

對於我的「/」的路線,我有以下幾點:

// router.js 

Router.configure({ 
    layout: 'layout' 
}); 

Router.route('/', function() { 
    this.render('welcome'); 
}); 

我的模板看起來像:

<!--main.html --> 

<head> 
    <title>App</title> 
</head> 

<body> 
</body> 

<template name='layout'> 
    <div id='container'> 
    {{> yield}} 
    </div> 
</template> 

<template name='welcome'> 
    <p>Welcome</p> 
</template> 

對於我的包,我最初嘗試只安裝iron:router插件。它似乎添加了鐵:核心,鐵:動態模板和鐵:佈局。因爲我已經單獨添加每個庫:

> meteor list 
iron:core    0.3.4 Iron namespace and utilities. 
iron:dynamic-template 0.4.1 Dynamically create and update templates and the... 
iron:layout   0.4.1 Dynamic layouts which enable rendering dynamic ... 
iron:router   0.9.4 Routing specifically designed for Meteor 
meteor-platform  1.1.1 Include a standard set of Meteor packages in yo... 
+1

像saimeunt寫道,沒有必要使用標籤 – yoK0 2014-10-03 02:15:15

回答

1

嘗試修改您的router.js到:

Router.configure({ 
    layoutTemplate: 'layout' // layoutTemplate, not layout 
}); 

Router.route('/',{ 
    // give the the route a name to help it find your welcome template 
    // let the default action function render the layout + template for you 
    name:"welcome" 
}); 

可以擺脫空體的過了,FYI您無需手動添加iron:router依賴:這就是一個包系統是第一個地方:)

+0

當使用上面的代碼時,我仍然無法找到模板。我可以用'{{> welcome}}'(不使用路由器)來渲染它。我修復了layoutTemplate配置,並嘗試在路由中對其進行硬編碼),例如http://eventedmind.github.io/iron-router/#layouts。 – Kombo 2014-10-03 02:23:49

+0

我試着重新安裝軟件包,因爲我手動添加了所有軟件,因爲我是偏執狂,他們沒有用'>流星列表顯示出來。路由器在渲染單個模板時工作正常,似乎無法對收益率做任何事情。 – Kombo 2014-10-03 02:25:30

+0

我似乎有這個語法的工作,它似乎沒有記錄,所以也許這是過時的:''Router.route('welcome',{ path:'/' });'謝謝你saimeunt! – Kombo 2014-10-03 02:36:01