【问题标题】:Iron Router inside package: cannot find templateIron Router 内包:找不到模板
【发布时间】:2015-07-04 21:41:54
【问题描述】:

我在一个包中使用 Iron Router,它抱怨找不到模板,即使我已经定义了它。

我在我的包中定义了一个名为layout 的模板:client/templates/shared/layout.html

我已经要求package.js 中的那个文件是这样的:

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  api.use('iron:router@1.0.9');

  api.addFiles([
    'both/routes.js'
  ], ['client', 'server']);

  api.addFiles([
    'client/templates/shared/layout.html',
    'client/templates/home.html'
  ], 'client');
});

我在路由定义文件中使用layout 模板both/routes.js

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

Router.route('/', {
  name: 'home',
  template: 'home'
});

在我的主应用程序中,我正在使用这个包。可以在.meteor/packages找到。

但是当我导航到/ 时,我得到了

Couldn't find a template named "layout" or "layout". Are you sure you defined it?

我尝试重新启动服务器但没有成功。我错过了什么?

【问题讨论】:

  • 猜猜,尝试先添加html文件,然后使用api.addFiles在包文件中添加路由器文件???
  • @Sasikanth 我尝试了api.use 和两个api.addFiles 的所有组合,但无法正常工作。

标签: meteor iron-router


【解决方案1】:

您可能还需要以下两个:

api.use(['templating'], 'client'); // The templating package

api.export('layout' ['client', 'server']); // Export your template.

【讨论】:

  • 添加api.use('templating', 'client'); 成功了。对于有类似问题的任何人,请参阅templating
猜你喜欢
  • 2015-02-12
  • 1970-01-01
  • 2014-01-25
  • 1970-01-01
  • 1970-01-01
  • 2015-08-31
  • 2015-12-22
  • 2015-04-04
  • 2015-08-31
相关资源
最近更新 更多